• No se han encontrado resultados

Corollary 3.4 (Polynomial Interpretations with Negative Constants Give Rise to Weakly Monotone Algebras [HM07]). Let A = (N, [·]A) be a polynomial interpretation with nega-

tive constants as in Definition 3.3. Then (A, ≥, >) is a weakly monotone algebra.

3.2 SMT-Based Automation

So now every interpretation for a function symbol f has the shape max(p0, 0) where p0

is a polynomial with a possibly negative constant and non-negative coefficients in the non-constant part. Thus, previously existing criteria for comparing two term interpreta- tions are not applicable anymore. The reason is that because of the max-operator, the interpretations are not polynomials any longer. Still, in this setting “max” is used only in a rather restricted way (one of the arguments is always the number 0). Therefore, in [HM07] Hirokawa and Middeldorp propose a sufficient criterion for showing that ` %A r

or `A r hold if the weakly monotone algebra (A, ≥, >) uses polynomial interpretations

over N where negative constants may occur. For this purpose, they use approximations for [`]A and [r]A which are polynomials. This way, existing criteria for comparing term

interpretations can be used again.

For the automatic synthesis of suitable interpretations, we are interested in parametric polynomial interpretations with variable coefficients. To find values for the coefficients for interpretations that do not use the max-operator, inequalities like [`]≥ [r] are transformed into Diophantine constraints by building α[`]−[r]≥0 etc., cf. Corollary 2.19. Here, we simply

require all coefficients of the polynomial [`]−[r] to be non-negative. However, now [`]−[r] contains the max-operator (i.e., it is no longer a polynomial). Thus, it is unclear how to transform [`]≥ [r] into Diophantine constraints.

To solve this problem, let us first regard concrete polynomial interpretations (where the coefficients are actual numbers). In [HM07], Hirokawa and Middeldorp present an approach to transform inequalities like [`] ≥ [r] into ordinary polynomial inequalities without the max-operator. The idea is to define an under-approximation [·]left and an over-approximation [·]right which are “proper” polynomials that do not contain “max” anymore. Then instead of [`] ≥ [r] one requires [`]left ≥ [r]right, which can be checked using techniques like the absolute positiveness criterion of Theorem 2.18.

Definition 3.5 ([·]left and [·]right for Concrete Interpretations [HM07]). For every poly- nomial p we denote its constant part by con(p) and the non-constant part p− con(p) by ncon(p), i.e., for a polynomial p as in Definition 3.3, we have con(p) = a0 and

ncon(p) = a1 xe111. . . xenn1 + . . . + am xe11m. . . xennm. For any concrete polynomial

and [t]rightA as follows:22 [t]left =      t if t is a variable

0 if t = f (t1, . . . , tn), ncon(p1) = 0, and 0 > con(p1)

p1 if t = f (t1, . . . , tn), otherwise [t]right =      t if t is a variable

ncon(p2) if t = f (t1, . . . , tn) and 0 > con(p2)

p2 if t = f (t1, . . . , tn), otherwise

where we have

• [f](x1, . . . , xn) = max(p0(x1, . . . , xn), 0) for a polynomial p0 with a possibly negative

constant and non-negative coefficients in the non-constant part, where p0 must be

weakly monotonic on Z, • p1 = p0([t1]left, . . . , [tn]left), and

• p2 = p0([t1]right, . . . , [tn]right).

Corollary 3.6 (Constant Part of a Polynomial). Let p(x1, . . . , xn) be a polynomial in the

variables x1, . . . , xn. Then con(p(x1, . . . , xn)) = p(0, . . . , 0).

As shown in [HM07], we have [t]left ≤ [t] ≤ [t]right for all terms t. Moreover, if the

polynomial interpretation has no negative constants, then we have [t]left = [t] = [t]right.

For the polynomial interpretation with [half]A = max(x1− 1, 0), we obtain

[half(x)]leftA = x− 1 [half(x)]A = max(x− 1, 0) [half(x)]rightA = x (3.10)

The reason is that for both i∈ {1, 2}, with [half](x) = max(x−1, 0) we have pi = x−1 and

thus ncon(pi) = x and con(pi) =−1. This example also indicates that this approximation

is incomplete. Obviously, half(x) %A half(x) holds since %A is reflexive, yet we have

[half(x)]leftA 6≥ [half(x)]rightA . However, as also indicated by our experiments, this sufficient criterion for ` % r is still very useful in practice.

Example 3.7 (Solving Bits, version 2 using [·]left and [·]right). Using the interpreta- tion from Example 3.2, we obtain [`]left > [r]right for the dependency pair (3.3) and [`]left ≥ [r]right for all rules ` → r ∈ {(2.1), (2.2), (2.3)}. Thus, the proof step with the reduction pair processor in Example 3.2 can now easily be verified automatically using the approximations [·]left and [·]right.

The disadvantage of Definition 3.5 is that one can only compute [t]left and [t]right for

3.2. SMT-Based Automation 43

concrete polynomial interpretations.23 However, if one wants to find the coefficients of the

polynomial interpretations automatically, then it would be better to start with parametric polynomial interpretations again where the coefficients ai in Definition 3.3 are left open

(i.e., they are variable coefficients).

In our example, we would use a parametric interpretation [·]B with [half]B(x1) =

max(a x1 + b, 0). Here, a may only be instantiated by natural numbers, whereas we

denote parameters like b that may be instantiated by integers in bold face. However, to compute [half(x)]leftB and [half(x)]rightB we would have to decide whether ncon(p1) = a x

and con(pi) = b are equal to or less than 0, respectively. This of course depends on the

instantiation of the parametric coefficients a and b.

Therefore, we now modify Definition 3.5 to make it suitable for parametric polynomial interpretations. The idea is to introduce new Diophantine variables24 bleftt and brightt for any term t to denote the constant parts of [t]left and [t]right, respectively. Note that [t]left is an under-approximation of [t], so bleftt can also take negative values. Similarly, [t]right is an over-approximation of [t], so it suffices to consider non-negative values for brightt (the constant part of [t]right is always non-negative, cf. Definition 3.5). Then we

still need to create Diophantine constraints αleftt and αrightt which guarantee that bleftt and brightt are instantiated correctly. To this end, we express the conditions ncon(p1) = 0 and

0 > con(pi) from Definition 3.5 as Diophantine constraints.

Definition 3.8 ([·]left and [·]right for Parametric Interpretations). For any parametric

polynomial interpretation [·]A such that every concretization [·]D(A) is weakly monotonic

on Z and for any term t, we define:

• If t is a variable, then [t]left = t, [t]right = t, αleft

t = true, and α right

t = true.

• If t = f(t1, . . . , tn), then25 [t]left = ncon(p1) + b left

t , [t]right = ncon(p2) + b right

t ,

αleftt = αtleft1 ∧ . . . ∧ αtleftn ∧ ( αncon(p1)=0∧ 0 > con(p1) → b left

t = 0)

∧ (¬(αncon(p1)=0∧ 0 > con(p1)) → b left

t = con(p1))

αrightt = αtright1 ∧ . . . ∧ αtrightn ∧ ( 0 > con(p2) → brightt = 0)

∧ (¬(0 > con(p2)) → b right

t = con(p2))

Here, both p1 and p2 are defined as in Definition 3.5, and αncon(p1)=0 is defined as in

Theorem 2.18.

23Thus, previous implementations for polynomial interpretations with negative constants like

TTT and AProVE simply test several choices for the coefficients. More sophisticated algorithms for systemati- cally finding coefficients like [CMTU05] only work for non-negative coefficients.

24Note that it can be helpful to use different ranges for different Diophantine variables. In particular, it is recommendable to use a larger range for the fresh variables bleftt and brightt , since they stand for the values of complex polynomials con(pi) which contain sums and multiplications of many other Diophantine variables.

25Note that according to Definition 3.5, [t]left = ncon(p

For [half]B(x1) = max(a x1+b, 0), t =half(x), and [t]B, we have ncon(p0) = a x, con(p0) =

b, and:

[half(x)]leftB = a x + bleftt and [half(x)]rightB = a x + brightt (3.11) αleftt = ((a = 0∧ 0 > b) → bleftt = 0) ∧ (¬(a = 0 ∧ 0 > b) → bleftt = b) (3.12)

αrightt = ((0 > b)→ brightt = 0) ∧ (¬(0 > b) → brightt = b) (3.13)

Theorem 3.9 shows that Definition 3.8 extends Definition 3.5 to parametric interpreta- tions correctly.

Theorem 3.9 (Correspondence of Definition 3.5 and 3.8). Let D be a Diophantine in- terpretation (which may only map bold variables also to negative numbers). Let [·]B be

a parametric polynomial interpretation, and let t be a term. Then D(αleftt ) = 1 implies D([t]left B ) = [t] left D(B) and D(α right t ) = 1 implies D([t] right B ) = [t] right D(B).

Proof. We use structural induction on t and only prove the part D([t]leftB ) = [t]leftD(B). The part D([t]rightB ) = [t]rightD(B) is proved in an analogous way.

In this proof, we write “for t we have p1A . . . ” to denote that with the interpretation [·]A, the polynomial p1 of Definition 3.5 or Definition 3.8 for t is p1A (analogously for p2).

Thus, assume D(αtleft) = 1. If t is a variable, then we have

D([t]left

B ) = D(t) by Definition 3.8

= t cf. Footnote 17 = [t]leftD(B)

Next, we regard the case t = f (t1, . . . , tn). For t, we have p1B = p0([t1]leftB , . . . , [tn]leftB )

and p1D(B) =D(p0)([t1]leftD(B), . . . , [tn]D(B)left ), where [f ]B(x1, . . . , xn) = max(p0(x1, . . . , xn), 0).

First consider the subcase ncon(p1D(B)) = 0, and 0 > con(p1D(B)). As D(αleftt ) = 1, we also have D(αleftti ) = 1 for all i ∈ {1, . . . , n}. So the induction hypothesis implies D([ti]leftB ) = [ti]leftD(B). Hence for t we have

D(p1B) = D(p0([t1] left B , . . . , [tn] left B )) = D(p0)(D([t1]leftB ), . . . ,D([tn]leftB ))

= D(p0)([t1]leftD(B), . . . , [tn]leftD(B)) by the induction hypothesis

= p1D(B)

Therefore, we also have

3.2. SMT-Based Automation 45

This implies26

ncon(p1D(B)) = 0 iff D(ncon(p1B)) = 0 iff D(αncon(p1B)=0) = 1

and

0 > con(p1D(B)) iff D(0 > con(p1D(B))) = 1. Therefore,D(αleftt ) = 1 impliesD(bleftt ) = 0. Thus,

D([t]left B ) = D(ncon(p1B) + bleftt ) = D(ncon(p1B)) +D(bleftt ) = ncon(p1D(B)) + 0 = 0 = [t]leftD(B)

Finally, for t = f (t1, . . . , tn) we regard the remaining subcase where ncon(p1D(B))6= 0 or

0≤ con(p1D(B)). Similar to the previous subcase, one can show thatD(αleftt ) = 1 implies D(bleft t ) = D(con(p1B)) = con(p1D(B)). Hence, D([t]left B ) = D(ncon(p1B) + bleftt ) = D(ncon(p1B)) +D(bleftt ) = ncon(p1D(B)) + con(p1D(B)) = p1D(B) = [t]leftD(B)

For example, letD be a Diophantine interpretation which turns the parametric polyno- mial interpretation [·]B into the concrete interpretation [·]A, where we haveD(a) = 1 and

D(b) = −1. Then indeed, D([half]B) = D(max(a x1+b, 0)) = max(x1 − 1, 0) = [half]A.

To satisfy the Diophantine constraints αleftt and αrightt in (3.12) and (3.13), we must have D(bleft

t ) =−1 and D(b right

t ) = 0. Then by (3.10) and (3.11), we indeed obtain

D([half(x)]left B ) = D(ax + b left t ) = x− 1 = [half(x)] left A D([half(x)]right B ) = D(ax + b right t ) = x = [half(x)] right A

To summarize, we now proceed as follows to automate the search for a polynomial interpretation with negative constants for a set of term constraints `  r or ` % r, as needed for the reduction pair processor:

26Note that by (2.24), α

p=0 requires that all coefficients of p must be 0. Thus, we indeed haveD(αp=0) = D(p = 0) for all Diophantine interpretations D.

(i) Fix a parametric polynomial interpretation [·]B and transform the inequalities ` r

or ` % r into [`]left − [r]right > 0 or [`]left − [r]right ≥ 0, respectively. Add the

conjunction of all corresponding constraints αleft` and αrightr , and add constraints to ensure that non-bold Diophantine variables are only instantiated with non-negative numbers.

(ii) Replace [`]left−[r]right > 0 by α

[`]left−[r]right > 0 and [`]left−[r]right ≥ 0 by α[`]left−[r]right ≥

0, respectively.

(iii) Use an SMT-NIA solver to determine a solution D for the resulting Diophantine constraint. If the SMT solver finds a satisfying Diophantine interpretation, in- stantiate the parametric polynomial interpretation [·]B to a concrete interpretation

[·]D(B). The corresponding weakly monotone algebra then induces a reduction pair

that solves the initial term constraints.

Given a DP problem (P, R), in practice one often searches for a reduction pair that ori- ents at least one rule fromP strictly and all other rules from P and the usable rules UR(P)

weakly. This can be expressed by the following constraint on terms, which [CGST12] calls the usable rule constraint :

^

`→r ∈ P ∪ UR(P)

` % r ∧ _

`→r ∈ P

`  r (3.14)

For the case of using a weakly monotonic algebra, these term constraints become the following constraint over the algebra:

^

`→r ∈ P ∪ UR(P)

[`]≥ [r] ∧ _

`→r ∈ P

[`] > [r] (3.15)

In the setting of this chapter, we obtain the following sufficient criterion: ^

`→r ∈ P ∪ UR(P)

[`]left ≥ [r]right ∧ _

`→r ∈ P

[`]left > [r]right (3.16)

In practice, one usually provides the SMT-NIA solver with additional information on the search space for the Diophantine variables. For instance, for solving term constraints in termination proving with polynomial interpretations, one usually only searches for values of the coefficients which are close to 0. This claim is substantiated by our experiments in [FGM+07] which indicate that for linear polynomial interpretations on N, searching for coefficients which exceed the value 6 is hardly beneficial in practice. Thus, it pays off to restrict the search space in order to benefit from knowledge about the application domain (here: solving term constraints) which is hard to recover for the SMT solver or even gets lost in the encoding process altogether.