Proving Correctness of Imperative Programs by Linearizing Constrained Horn Clauses

We present a method for verifying the correctness of imperative programs which is based on the automated transformation of their specifications. Given a program prog, we consider a partial correctness specification of the form $\{\varphi\}$ prog $\{\psi\}$, where the assertions $\varphi$ and $\psi$ are predicates defined by a set Spec of possibly recursive Horn clauses with linear arithmetic (LA) constraints in their premise (also called constrained Horn clauses). The verification method consists in constructing a set PC of constrained Horn clauses whose satisfiability implies that $\{\varphi\}$ prog $\{\psi\}$ is valid. We highlight some limitations of state-of-the-art constrained Horn clause solving methods, here called LA-solving methods, which prove the satisfiability of the clauses by looking for linear arithmetic interpretations of the predicates. In particular, we prove that there exist some specifications that cannot be proved valid by any of those LA-solving methods. These specifications require the proof of satisfiability of a set PC of constrained Horn clauses that contain nonlinear clauses (that is, clauses with more than one atom in their premise). Then, we present a transformation, called linearization, that converts PC into a set of linear clauses (that is, clauses with at most one atom in their premise). We show that several specifications that could not be proved valid by LA-solving methods, can be proved valid after linearization. We also present a strategy for performing linearization in an automatic way and we report on some experimental results obtained by using a preliminary implementation of our method.


Introduction
One of the most established methodologies for specifying and proving the correctness of imperative programs is based on the Floyd-Hoare axiomatic approach (see (Hoare 1969), and also (Apt et al. 2009) for a recent presentation dealing with both sequential and concurrent programs). By following this approach, the partial correctness of a program prog is formalized by a triple {ϕ} prog {ψ}, also called partial correctness specification, where the precondition ϕ and the postcondition ψ are assertions in first order logic, meaning that if the input values of prog satisfy ϕ and program execution terminates, then the output values satisfy ψ.
It is well-known that the problem of checking partial correctness of programs with respect to given preconditions and postconditions is undecidable. In particular, the undecidability of partial correctness is due to the fact that in order to prove in Hoare logic the validity of a triple {ϕ} prog {ψ}, one has to look for suitable auxiliary assertions, the so-called invariants, in an infinite space of formulas, and also to cope with the undecidability of logical consequence.
Thus, the best way of addressing the problem of the automatic verification of programs is to design incomplete methods, that is, methods based on restrictions of first order logic, which work well in the practical cases of interest. To achieve this goal, some methods proposed in the literature in recent years use linear arithmetic constraints as the assertion language and constrained Horn clauses as the formalism to express and reason about program correctness (Bjørner et al. 2012;De Angelis et al. 2014a;Grebenshchikov et al. 2012;Jaffar et al. 2012;Peralta et al. 1998;Podelski and Rybalchenko 2007;Rümmer et al. 2013).
Constrained Horn clauses are clauses with at most one atom in their conclusion and a conjunction of atoms and constraints over a given domain in their premise. In this paper we will only consider constrained Horn clauses with linear arithmetic constraints. The use of this formalism has the advantage that logical consequence for linear arithmetic constraints is decidable and, moreover, reasoning within constrained Horn clauses is supported by very effective automated tools, such as Satisfiability Modulo Theories (SMT) solvers (de Moura and Bjørner 2008;Cimatti et al. 2013;Rümmer et al. 2013) and constraint logic programming (CLP) inference systems (Jaffar and Maher 1994). However, current approaches to correctness proofs based on constrained Horn clauses have the disadvantage that they only consider specifications whose preconditions and postconditions are linear arithmetic constraints.
In this paper we overcome this limitation and propose an approach to proving general specifications of the form {ϕ} prog {ψ}, where ϕ and ψ are predicates defined by a set of possibly recursive constrained Horn clauses (not simply linear arithmetic constraints), and prog is a program written in a C-like imperative language.
First, we indicate how to construct a set PC of constrained Horn clauses (PC stands for partial correctness), starting from: (i) the assertions ϕ and ψ, (ii) the program prog, and (iii) the definition of the operational semantics of the language in which prog is written, such that, if PC is satisfiable, then the partial correctness specification {ϕ} prog {ψ} is valid.
Then, we formally show that there are sets PC of constrained Horn clauses encoding partial correctness specifications, whose satisfiability cannot be proved by current methods, here collectively called LA-solving methods (LA stands for linear arithmetic). This limitation is due to the fact that LA-solving methods try to prove satisfiability by interpreting the predicates as linear arithmetic constraints.
For these problematic specifications, the set PC of constrained Horn clauses contains nonlinear clauses, that is, clauses with more than one atom in their premise.
Next, we present a transformation, which we call linearization, that converts the set PC into a set of linear clauses, that is, clauses with at most one atom in their premise. We show that linearization preserves satisfiability and also increases the power of LA-solving, in the sense that several specifications that could not be proved valid by LA-solving methods, can be proved valid after linearization. Thus, linearization followed by LA-solving is strictly more powerful than LA-solving alone.
The paper is organized as follows. In Section 2 we show how a class of partial correctness specifications can be translated into constrained Horn clauses. In Section 3 we prove that LA-solving methods are inherently incomplete for proving the satisfiability of constrained Horn clauses. In Section 4 we present a strategy for automatically performing the linearization transformation, we prove that it preserves LA-solvability, and (in some cases) it is able to transform constrained Horn clauses that are not LA-solvable into constrained Horn clauses that are LA-solvable. Finally, in Section 5 we report on some preliminary experimental results obtained by using a proof-of-concept implementation of the method.

Translating Partial Correctness into Constrained Horn Clauses
We consider a C-like imperative programming language with integer variables, assignments, conditionals, while loops, and goto's. An imperative program is a sequence of labeled commands (or commands, for short), and in each program there is a unique halt command that, when executed, causes program termination.
The semantics of our language is defined by a transition relation, denoted =⇒, between configurations. Each configuration is a pair ℓ : c, δ of a labeled command ℓ : c and an environment δ. An environment δ is a function that maps every integer variable identifier x to its value v in the integers Z. The definition of the relation =⇒ is similar to that of the 'small step' operational semantics presented in (Reynolds 1998), and is omitted. Given a program prog, we denote by ℓ 0 : c 0 its first labeled command.
We assume that all program executions are deterministic in the sense that, for every environment δ 0 , there exists a unique, maximal (possibly infinite) sequence of configurations, called computation sequence, of the form: ℓ 0 : c 0 , δ 0 =⇒ ℓ 1 : c 1 , δ 1 =⇒ · · ·. We also assume that every finite computation sequence ends in the configuration ℓ h : halt, δ n , for some environment δ n . We say that a program prog terminates for δ 0 iff the computation sequence starting from the initial configuration ℓ 0 : c 0 , δ 0 is finite.

Specifying Program Correctness
First we need the following notions about constraints, constraint logic programming, and constrained Horn clauses. For related notions with which the reader is not familiar, he may refer to (Jaffar and Maher 1994;Lloyd 1987).
A constraint is a linear arithmetic equality (=) or inequality (>) over the integers Z, or a conjunction or a disjunction of constraints. For example, 2 ·X ≥ 3 ·Y − 4 is a constraint. We feel free to say 'linear arithmetic constraint', instead of 'constraint'. We denote by C LA the set of all constraints. An atom is an atomic formula of the form p(t 1 , . . . , t m ), where p is a predicate symbol not in {=, >} and t  , . . . , t m are terms. Let Atom be the set of all atoms. A definite clause is an implication of the form A ← c, G, where in the conclusion (or head ) A is an atom, and in the premise (or body) c is a constraint, and G is a (possibly empty) conjunction of atoms. A constrained goal (or simply, a goal ) is an implication of the form false ← c, G. A constrained Horn clause (CHC) (or simply, a clause) is either a definite clause or a constrained goal. A constraint logic program (or simply, a CLP program) is a set of definite clauses. A clause over the integers is a clause that has no function symbols except for integer constants, addition, and multiplication by integer constants.
The semantics of a constraint c is defined in terms of the usual interpretation, denoted by LA, over the integers Z. We write LA |= c to denote that c is true in LA. Given a set S of constrained Horn clauses, an LA-interpretation is an interpretation for the language of S that agrees with LA on the language of the constraints. An LA-model of S is an LA-interpretation that makes all clauses of S true. A set of constrained Horn clauses is satisfiable if it has an LA-model. A CLP program P is always satisfiable and has a least LA-model, denoted M (P ). We have that a set S of constrained Horn clauses is satisfiable iff S = P ∪G, where P is a CLP program, G is a set of goals, and M (P ) |= G. Given a first order formula ϕ, we denote by ∃(ϕ) its existential closure and by ∀(ϕ) its universal closure.
Throughout the paper we will consider partial correctness specifications which are particular triples of the form {ϕ} prog {ψ} defined as follows.
We say that a functional Horn specification {ϕ} prog {ψ} is valid , or prog is partially correct with respect to ϕ and ψ, iff for all environments δ 0 and δ n , if M (Spec) |= pre(δ 0 (z 1 ), . . . , δ 0 (z s )) holds (in words, δ 0 satisfies pre) and ℓ 0 : c 0 , δ 0 =⇒ * ℓ h : halt, δ n holds (in words, prog terminates for δ 0 ) holds, then M (Spec) |= f (δ 0 (z 1 ), . . . , δ 0 (z s ), δ n (z k )) holds (in words, δ n satisfies the postcondition). The relation r prog computed by prog according to the operational semantics of the imperative language, is defined by the CLP program OpSem made out of: (i) the following clause R (where, as usual, variables are denoted by upper-case letters): where: (i.1) initCf (C 0 ,P 1 ,. . . ,P s ) represents the initial configuration C 0 , where the variables z 1 ,. . .,z s are bound to the values P 1 ,. . .,P s , respectively, and pre(P 1 ,. . .,P s ) holds, (i.2) reach(C 0 , C h ) represents the transitive closure =⇒ * of the transition relation =⇒, which in turn is represented by a predicate tr (C 1 , C 2 ) that encodes the operational semantics, that is, the interpreter of our imperative language, by relating a source configuration C 1 to a target configuration C 2 , (i.3) finalCf (C h , Z k ) represents the final configuration C h , where the variable z k is bound to the value Z k , and (ii) the clauses for the predicates pre(P 1 , . . . , P s ) and tr(C 1 ,C 2 ). The clauses for the predicate tr(C 1 ,C 2 ) are defined as indicated in (De Angelis et al. 2014a), and are omitted for reasons of space.
Example 1 (Fibonacci Numbers) Let us consider the following program fibonacci, that returns as value of u the n-th Fibonacci number, for any n (≥ 0), having initialized u to 1 and v to 0. 0: while (n>0) { t=u; u=u+v; v=t; n=n-1 } fibonacci h: halt The following is a functional Horn specification of the partial correctness of the program fibonacci: {n=N, N>=0, u=1, v=0, t=0} fibonacci {fib(N,u)} ( ‡) where N is a parameter and fib is defined by the following CLP program: For reasons of conciseness, in the above specification ( ‡) we have slightly deviated from Definition 1. In particular, we did not introduce the predicate symbol pre, and in the precondition and postcondition we did not introduce the parameters which have constant values.
The relation r fibonacci computed by the program fibonacci according to the operational semantics, is defined by the following CLP program: where: (i) firstCmd(LC) holds for the command with label 0 of the program fibonacci; (ii) env((x,X),E) holds iff in the environment E the variable x is bound to the value of X; (iii) in the initial configuration C0 the environment E binds the variables n, u, v, t to the values N (>=0), 1, 0, and 0, respectively; and (iv) haltCmd(LC) holds for the labeled command h: halt.

Encoding Specifications into Constrained Horn Clauses
In this section we present the encoding of the validity problem of functional Horn specifications into the satisfiability problem of CHC's.
For reasons of simplicity we assume that in Spec no predicate depends on f (possibly, except for f itself), that is, Spec can be partitioned into two sets of clauses, call them F def and Aux , where F def is the set of clauses with head predicate f, and f does not occur in Aux. Theorem 1 (Partial Correctness) Let F pcorr be the set of goals derived from F def as follows : where Z is a new variable, and (3) goal G is replaced by the following two goals: The proof of this theorem and of the other facts presented in this paper can be found in the online appendix. In our Fibonacci example (see Example 1) the set F def of clauses is the entire set Spec fibonacci and Aux = ∅. According to Points (1)-(3) of Theorem 1, from Spec fibonacci we derive the following six goals: Thus, in order to prove the validity of the specification ( ‡) above, since Aux = ∅, it is enough to show that the set PC fibonacci = {G1,. . . , G6} ∪ OpSem fibonacci of CHC's is satisfiable.

A Limitation of LA-solving Methods
Now we show that there are sets of CHC's that encode partial correctness specifications whose satisfiability cannot be proved by LA-solving methods. A symbolic interpretation is a function Σ : Atom −→ C LA such that, for every A ∈ Atom and substitution ϑ, Σ(Aϑ) = Σ(A)ϑ. Given a set S of CHC's, a symbolic We say that a set S of CHC's is LA-solvable if there exists an LA-solution of S . Clearly, if a set of CHC's is LA-solvable, then it is satisfiable. The converse does not hold as we now show.

Theorem 2
There are sets of constrained Horn clauses which are satisfiable and not LA-solvable.
Proof. Let PC fibonacci be the set of clauses that encode the validity of the Fibonacci specification ( ‡). PC fibonacci is satisfiable, because r fibonacci(N, F) holds iff F is the N-th Fibonacci number, and hence the bodies of G1, . . . , G6 are false. (This fact will also be proved by the automatic method presented in Section 4.) Now we prove, by contradiction, that PC fibonacci is not LA-solvable. Suppose that there exists an LA-solution Σ of PC fibonacci . Let Σ(r fibonacci(N, F)) be a constraint c(N, F). To keep our proof simple, we assume that c(N, F) is defined by a conjunction of linear arithmetic inequalities (that is, c(N, F) is a convex constraint), but our argument can easily be generalized to any constraint in C LA . By the definition of LA-solution, we have that: Property (P 1) follows from the fact that, in particular, an LA-solution satisfies goal G5. Property (P 2) follows from the fact that an LA-solution satisfies all clauses of OpSem fibonacci and M (OpSem fibonacci ) defines the least r fibonacci relation that satisfies those clauses.
From Property (P 2) and from the fact that r fibonacci(N, F) holds iff F is the N-th Fibonacci number (and hence F is an exponential function of N), it follows that Figure 1. The relation r fibonacci(N,F) and the convex constraint c(N,F).
By replacing c(N1,F1), c(N2,F2), and c(N3,F3) by the corresponding conjunctions of atomic constraints of the forms (A) and (B), and eliminating the occurrences of F1, F2, N2, and N3, from (P 1) we get: where, for i = 1, . . . , n, p i is a linear polynomial in the variable N1. Then, the constraint N1≥0, F3 > p 1 , . . . , F3 > p n is satisfiable and Property (P 3) is false. Thus, the assumption that PC fibonacci is LA-solvable is false, and we get the thesis.

Increasing the Power of LA-Solving Methods by Linearization
A weakness of the LA-solving methods is that they look for LA-solutions constructed from single atoms, and by doing so they may fail to discover that a goal is satisfiable because a conjunction of atoms in its premise is unsatisfiable, in spite of the fact that each of its conjoint atoms is satisfiable. For instance, in our Fibonacci example the premise of goal G5 contains three atoms with predicate r fibonacci and our proof of Section 3 shows that, even if the premise of G5 is unsatisfiable, there is no constraint which is an LA-solution of the clauses defining r fibonacci that, when substituted for each r fibonacci atom, makes that premise false. Thus, the notion of LA-solution shows some weakness when dealing with nonlinear clauses, that is, clauses whose premise contains more than one atom (besides constraints). In this section we present an automatic transformation of constrained Horn clauses that has the objective of increasing the power of LA-solving methods.
The core of the transformation, called linearization, takes a set of possibly nonlinear constrained Horn clauses and transforms it into a set of linear clauses, that is, clauses whose premise contains at most one atom (besides constraints). After performing linearization, the LA-solving methods are able to exploit the interactions among several atoms, instead of dealing with each atom individually. In particular, an LA-solution of the linearized set of clauses will map a conjunction of atoms to a constraint. We will show that linearization preserves the existence of LA-solutions and, in some cases (including our Fibonacci example), transforms a set of clauses which is not LA-solvable into a set of clauses that is LA-solvable.
Our transformation technique is made out of the following two steps: (1) RI: Removal of the interpreter, and (2) LIN: Linearization. These steps are performed by using the transformation rules for CLP programs presented in (Etalle and Gabbrielli 1996), that is: unfolding (which consists in applying a resolution step and a constraint satisfiability test), definition (which introduces a new predicate defined in terms of old predicates), and folding (which redefines old predicates in terms of new predicates introduced by the definition rule).

RI: Removal of the Interpreter
This step is a variant of the removal of the interpreter transformation presented in (De Angelis et al. 2014a). In this step a specialized definition for r prog is derived by transforming the CLP program OpSem, thereby getting a new CLP program OpSem RI where there are no occurrences of the predicates initCf, finalCf, reach, and tr, which as already mentioned encodes the interpreter of the imperative language in which prog is written. (See online appendix for more details.) By a simple extension of the results presented in (De Angelis et al. 2014a), it can be shown that the RI transformation always terminates, preserves satisfiability, and transforms OpSem into a set of linear clauses over the integers. It can also be shown that the removal of the interpreter preserves LA-solvability. Thus, we have the following result.

Theorem 3
Let OpSem be a CLP program constructed starting from any given imperative program prog. Then the RI transformation terminates and derives a CLP program OpSem RI such that: (1) OpSem RI is a set of linear clauses over the integers; ( In the Fibonacci example, the input of the RI transformation is OpSem fibonacci . The output of the RI transformation consists of the following three clauses: where r is a new predicate symbol introduced by the RI transformation. As stated by Theorem 3, OpSem RI is a set of clauses over the integers. Since the clauses of the specification Spec define computable functions from Z s to Z, without loss of generality we may assume that also the clauses in Aux ∪ F pcorr are over the integers (Sebelik and Stepánek 1982). From now on we will only deal with clauses over the integers, and we will feel free to omit the qualification 'over the integers'.

LIN: Linearization
The linearization transformation takes as input the set OpSem RI ∪ Aux ∪ F pcorr of constrained Horn clauses and derives a new, equisatisfiable set TransfCls of linear constrained Horn clauses.
In order to perform linearization, we assume that Aux is a set of linear clauses. This assumption, which is not restrictive because any computable function on the integers can be encoded by linear clauses (Sebelik and Stepánek 1982), simplifies the proof of termination of the transformation.
The linearization transformation is described in Figure 2. Its input is constructed by partitioning OpSem RI ∪ Aux ∪ F pcorr into a set LCls of linear clauses and a set NLGls of nonlinear goals. LCls consists of Aux, OpSem RI (which, by Theorem 3, is a set of linear clauses), and the subset of linear goals in F pcorr . NLGls consists of the set of nonlinear goals in F pcorr .
When applying linearization we use the following transformation rule.  It is easy to see that, since LCls is a set of linear clauses, only a finite number of new predicates can be introduced by any sequence of applications of Definition & Folding, and hence the linearization transformation terminates. Moreover, the use of the unfolding, definition, and folding rules according to the conditions indicated in (Etalle and Gabbrielli 1996), guarantees the equivalence with respect to the least LA-model, and hence the equisatisfiability of LCls ∪ Gls and TransfCls. Thus, we have the following result.

Theorem 4 (Termination and Correctness of Linearization)
Let LCls be a set of linear clauses and Gls be a set of nonlinear goals. The linearization transformation terminates for the input set of clauses LCls ∪ Gls, and the output TransfCls is a set of linear clauses. Moreover, LCls ∪ Gls is satisfiable iff TransfCls is satisfiable.
Let us consider again the Fibonacci example. We apply the linearization transformation to the set {E1,E2,E3} of linear clauses, and to the nonlinear goal G5. For brevity, we omit to consider the cases where the goals G1, . . . ,G4,G6 are taken as input to the linearization transformation.
After Initialization we have that NLCls = {G5}, Defs = ∅, and TransfCls = {E1,E2,E3}. By applying the Unfolding step to G5 we derive: The transformation terminates when all clauses derived by unfolding can be folded using clauses in Defs, without introducing new predicates. The output of the transformation is a set of linear clauses (listed in the online appendix) which is LA-solvable, as reported on line 4 of Table 1 in the next section.
In general, there is no guarantee that we can automatically transform any given satisfiable set of clauses into an LA-solvable one. In fact, such a transformation cannot be algorithmic because, for constrained Horn clauses, the problem of satisfiability is not semidecidable, while the problem of LA-solvability is semidecidable (indeed, the set of symbolic interpretations is recursively enumerable and the problem of checking whether or not a symbolic interpretation is an LA-solution is decidable). However, the linearization transformation cannot decrease LA-solvability, as the following theorem shows. Theorem 5 (Monotonicity with respect to LA-Solvability) Assume that by applying the linearization transformation to a set LCls ∪ Gls of CHC's, we obtain a set TransfCls. If LCls ∪ Gls is LA-solvable, then TransfCls is LA-solvable.
Since there are cases where LCls ∪ Gls is not LA-solvable, while TransfCls is LA-solvable (see the Fibonacci example above and some more examples in the following section), as a consequence of Theorem 5 we get that the combination of LA-solving and linearization is strictly more powerful than LA-solving alone.

Experimental Results
We have implemented our verification method by using the VeriMAP system (De Angelis et al. 2014b). The implemented tool consists of four modules, which we have depicted in Figure 3. The first module, given the imperative program prog and its specification Spec, generates the set PC of constrained Horn clauses (see Theorem 1). PC is then given as input to the module RI that removes the interpreter. Then, the module LIN performs the linearization transformation. Finally, the resulting linear clauses are passed to the LA-solver, consisting of VeriMAP together with an SMT solver, which is either Z3 (de Moura and Bjørner 2008) or MathSAT (Cimatti et al. 2013) or Eldarica (Rümmer et al. 2013). We performed an experimental evaluation on a set of programs taken from the literature, including some programs from (Felsing et al. 2014) obtained by applying strength reduction, a real-world optimization technique 1 . In Table 1 we report the results of our experiments 2 .
One can see that linearization takes very little time compared to the total verification time. Moreover, linearization is necessary for the verification of 14 out of 19 programs (including fibonacci), which otherwise cannot be proved correct with respect to their specifications. In the two columns under LA-solving-1 we report the results obtained by giving as input to the Z3 and Eldarica solvers the set PC generated by the RI module. Under LA-solving-1 we do not have a column for MathSAT, because the version of this solver used in our experiments (namely, MSATIC3) cannot deal with nonlinear CHC's, and therefore it cannot be applied before linearization. In the last three columns of Table 1 we report the results obtained by giving as input to VeriMAP (and the solvers Z3, MatSAT, and Eldarica, respectively) the clauses obtained after linearization.
Unsurprisingly, for the verification problems where linearization is not necessary, our technique may deteriorate the performance, although in most of these problems the solving time does not increase much.

Conclusions and Related Work
We have presented a method for proving partial correctness specifications of programs, given as Hoare triples of the form {ϕ} prog {ψ}, where the assertions ϕ and ψ are predicates defined by a set of possibly recursive, definite CLP clauses. Our verification method is based on: Step (1) a translation of a given specification into a set of constrained Horn clauses (that is, a CLP program together with one or more goals), Step (2) an unfold/fold transformation strategy, called linearization, which derives linear clauses (that is, clauses with at most one atom in their body), and Step (3) an LA-solver that attempts to prove the satisfiability of constrained Horn clauses by interpreting predicates as linear arithmetic constraints.
We have formally proved that the method which uses linearization is strictly more powerful than the method that applies Step (3) immediately after Step (1). We have also developed a proof-of-concept implementation of our method by using the Ver-iMAP verification system (De Angelis et al. 2014b) together with various state-ofthe-art solvers (namely, Z3 (de Moura and Bjørner 2008), MathSAT (Cimatti et al. 2013), and Eldarica (Rümmer et al. 2013)), and we have shown that our method works on several verification problems. Although these problems refer to quite simple specifications, some of them cannot be solved by using the above mentioned solvers alone.
The use of transformation-based methods in the field of program verification has recently gained popularity (see, for instance, (Albert et al. 2007;De Angelis et al. 2014a;Fioravanti et al. 2013;Kafle and Gallagher 2015;Leuschel and Massart 2000;Lisitsa and Nemytykh 2008;Peralta et al. 1998)). However, fully automated methods based on various notions of partial deduction and CLP program specialization cannot achieve the same effect as linearization. Indeed, linearization requires the introduction of new predicates corresponding to conjunctions of old predicates, whereas partial deduction and program specialization can only introduce new predicates that correspond to instances of old predicates. In order to derive linear clauses, one could apply conjunctive partial deduction (De Schreye et al. 1999), which essentially is equivalent to unfold/fold transformation. However, to the best of our knowledge, this application of conjunctive partial deduction to the field of program verification has not been investigated so far.
The use of linear arithmetic constraints for program verification has been first proposed in the field of abstract interpretation (Cousot and Cousot 1977), where these constraints are used for approximating the set of states that are reachable during program execution (Cousot and Halbwachs 1978). In the field of logic programming, abstract interpretation methods work similarly to LA-solving for constrained Horn clauses, because they both look for interpretations of predicates as linear arithmetic constraints that satisfy the program clauses (see, for instance, (Benoy and King 1997)). Thus, abstract interpretation methods suffer from the same theoretical limitations we have pointed out in this paper for LA-solving methods.
One approach that has been followed for overcoming the limitations related to the use of linear arithmetic constraints is to devise methods for generating polynomial invariants and proving specifications with polynomial arithmetic constraints (Rodríguez-Carbonell and Kapur 2007a;Rodríguez-Carbonell and Kapur 2007b). This approach also requires the development of solvers for polynomial constraints, which is a very complex task on its own, as in general the satisfiability of these constraints on the integers is undecidable (Matijasevic 1970). In contrast, the approach presented in this paper has the objective of transforming problems which would require the proof of nonlinear arithmetic assertions into problems which can be solved by using linear arithmetic constraints. We have shown some examples (such as the fibonacci program) where we are able to prove specifications whose post-condition is an exponential function.
An interesting issue for future research is to identify general criteria to answer the following question: Given a class D of constraints and a class H of constrained Horn clauses, does the satisfiability of a finite set of clauses in H imply its D-solvability? Theorem 2 provides a negative answer to this question when D is the class of LA constraints and H is the class of all constrained Horn clauses.

Acknowledgments
We thank the participants in the Workshop VPT '15 on Verification and Program Transformation, held in London on April 2015, for their comments on a preliminary version of this paper. This work has been partially supported by the National Group of Computing Science (GNCS-INDAM).

Removal of the Interpreter
Here we report the variant of the transformation presented in (De Angelis et al. 2014a) that we use in this paper to perform the removal of the interpreter. In this transformation we use the function Unf (C , A, Cls) defined as the set of clauses derived by unfolding a clause C with respect to an atom A using the set Cls of clauses (see the unfolding rule in Section 4.2).
those atoms have no recursive clauses, (ii) by the definition of the semantics of the imperative program, the repeated unfolding of an atom of the form reach(cf 1 , cf 2 ) eventually derives a new reach(cf 3 , cf 4 ) atom where cf 3 is either a final configuration or a configuration associated with a while or goto command, and in both cases unfolding terminates. The termination of the Definition & Folding step follows from the fact that SpC is a finite set of clauses. The outer while loop terminates because a finite set of new predicate definitions of the form newp(V ) ← reach(cf 1 , cf 2 ) can be introduced. Indeed, each configuration cf is represented as a term cf(LC,E)), where LC is a labeled command and E is an environment (see Example 1). An environment is represented as a list of (v , X ) pairs where v is a variable identifier and X is its value, that is, a logical variable whose value may be subject to a given constraint. Considering that: (i) the labeled commands and the variable identifiers occurring in an imperative program are finitely many, and (ii) predicate definitions of the form newp(V ) ← reach(cf 1 , cf 2 ) abstract away from the constraints that hold on the logical variables occurring in cf 1 and cf 2 , we can conclude that there are only finitely many such clauses (modulo variable renaming).
Point 1: OpSem RI is a set of linear clauses over the integers. By construction, every clause in OpSem RI is of the form H ← c, B , where (i) H is either r prog (P 1 , . . . ,P s ,Z k ) or newp(V ), for some new predicate newp and tuple of variables V , and (ii) B is either absent or of the form newp(V ), for some new predicate newp and tuple of variables V . Thus, every clause is a linear clause over the integers.
Suppose that OpSem ∪ Aux ∪ F pcorr is LA-solvable, and let Σ be an LA-solution of OpSem ∪ Aux ∪ F pcorr . Now we construct an LA-solution Σ RI of OpSem RI ∪ Aux ∪ F pcorr . To this purpose it is enough to define a symbolic interpretation for the new predicates introduced by RI.
For any predicate newp introduced by RI via a clause of the form: we define a symbolic interpretation as follows: Σ RI (newp(V )) = Σ(reach(cf 1 , cf 2 )) Moreover, Σ RI is identical to Σ for the atoms with predicate occurring in OpSem.
Now we have to prove that Σ RI is indeed an LA-solution of OpSem RI ∪ Aux ∪ F pcorr . This proof is similar to the proof of Theorem 5 (actually, simpler, because RI introduces new predicates defined by single atoms, while LIN introduces new predicates defined by conjunctions of atoms), and is omitted.

Proof of Theorem 4
Let LCls be a set of linear clauses and Gls be a set of nonlinear goals. We split the proof of Theorem 4 in three parts: Termination: The linearization transformation LIN terminates for the input set of clauses LCls ∪ Gls; Linearity: The output TransfCls of LIN is a set of linear clauses; Equisatisfiability: LCls ∪ Gls is satisfiable iff TransfCls is satisfiable.
(Termination) Each Unfolding and Definition & Folding step terminates. Thus, in order to prove the termination of LIN it is enough to show that the while loop is executed a finite number of times, that is, a finite number of clauses are added to NLCls. We will establish this finiteness property by showing that there exists an integer M such that every clause added to NLCls is of the form: newp(X 1 , . . . , X t ) ← A 1 , . . . , A k ( †2) where: (i) k ≤ M , (ii) for i = 1, . . . , k , A i is of the form p(X 1 , . . . , X m ), and (iii) {X 1 , . . . , X t } ⊆ vars(A 1 , . . . , A k ).
Indeed, let M be the maximal number of atoms occurring in the body of a goal in Gls, to which NLCls is initialized. Now let us consider a clause C in NLCls and assume that in the body of C there are at most M atoms. The clauses in the set LCls used for unfolding C are linear, and hence in the body of each clause belonging to the set U (C ) obtained after the Unfolding step, there are at most M atoms. Thus, each clause in U (C ) is of the form H ← c, A 1 , . . . , A k , with k ≤ M . Since the body of every new clause introduced by the subsequent Definition & Folding step is obtained by dropping the constraint from the body of a clause in U (C ), we have that every clause added to NLCls is of the form ( †2), with k ≤ M . Thus, LIN terminates.
(Linearity) TransfCls is initialized to the set LCls of linear clauses. Moreover, each clause added to TransfCls is of the form H ← c, newp(X 1 , . . . , X t ), and hence is linear.
(Equisatisfiability) In order to prove that LIN ensures equisatisfiability, let us adapt to our context the basic notions about the unfold/fold transformation rules for CLP programs presented in (Etalle and Gabbrielli 1996).
Besides the unfolding rule of Section 4.2, we also introduce the following definition and folding rules.
Definition Rule. By definition we introduce a clause of the form newp(X ) ← G, where newp is a new predicate symbol and X is a tuple of variables occurring in G.
Folding Rule. Given a clause E : H ← c, G and a clause D : newp(X ) ← G intro-duced by the definition rule. Suppose that, X = vars(G) ∩ vars(H,c). Then by folding E using D we derive H ← c, newp(X ).
From a set Cls of clauses we can derive a new set TransfCls of clauses either by adding a new clause to Cls using the definition rule or by: (i) selecting a clause C in Cls, (ii) deriving a new set TransfC of clauses using one or more transformation rules among unfolding and folding, and (iii) replacing C by TransfC in Cls. We can apply a new sequence of transformation rules starting from TransfCls and iterate this process at will.
The following theorem is an immediate consequence of the correctness results for the unfold/fold transformation rules of CLP programs (Etalle and Gabbrielli 1996).
Theorem 6 (Correctness of the Transformation Rules) Let the set TransfCls be derived from Cls by a sequence of applications of the unfolding, definition and folding transformation rules. Suppose that every clause introduced by the definition rule is unfolded at least once in this sequence. Then, Cls is satisfiable iff TransfCls is satisfiable. Now, equisatisfiability easily follows from Theorem 6. Indeed, the Unfolding and Definition & Folding steps of LIN are applications of the unfolding, definition, and folding rules (strictly speaking, the rewriting performed after unfolding is not included among the transformation rules, but obviously preserves all LAmodels). Moreover, every clause introduced during the Definition & Folding step is added to NCls and unfolded in a subsequent step of the transformation. Thus, the hypotheses of Theorem 6 are fulfilled, and hence we have that LCls ∪ Gls is satisfiable iff TransfCls is satisfiable.
Linearized clauses for Fibonacci. The set of linear constrained Horn clauses obtained after applying LIN is made out of clauses E1, E2, E3, and C3, together with the following clauses: