3. CONTEXTO Y PROBLEMÁTICA
3.4 Problemática y justificación
is positive and π(vi−) is negative.
1. Let vexp v vexp0 be a constraint in C. Then, if π |= {vexp0+
i v
vexp+i ,vexp−i vvexp0−i }, then πv |=vexpvvexp0.
2. Let ae ≤ ae0 be a constraint in C. Then, if π |= ae+ ≤ ae0+ then
πv |=ae≤ae0. Proof.
1. Follows by Lemma 6.6.15 and Lemma 6.6.9. 2. Follows by Lemma 6.6.15.
2
Theorem 6.6.17 (Soundness and completeness of the reduction) Let C be a conjunction of subtyping and arithmetic constraints. Then there exists a valuationπ withπ|=C iff there exists a valuation π0 withπ0 |=Ctree such that, for eachv∈Vars(C)holdsπ0(vi+)is positive andπ0(vi−)is negative andCclass holds.
Proof.
Case “⇒” Follows by Lemma 6.6.13.
Case “⇐” Follows by Lemma 6.6.16.
2
6.6.4 Algorithm for solving subtyping and arithmetic con- straints
In this section we shall present a heuristic algorithm for solving a conjunction of subtyping and arithmetic constraints, by first reducing the constraints to systems of constraints, and then applying the heuristic algorithm for solving systems of constraints, described in Section 6.5.4. The algorithm consists of the steps shown in Fig. 6.14.
First, we reduce the conjunction of subtyping and arithmetic constraints C to the system of constraints Ctree and the set of subtyping judgements
Cclass. Then, we create a set of negative variablesX− and add eachv− i to it.
For proving the soundness of the reduction (Theorem 6.6.17) we require that the values for the positive tree variablesv+i are positive trees and that the values for the negative tree variables vi− are negative trees. Recall that an infinite tree is positive if some of its subtrees are positive (the ones that we obtain by applying the labels inL+), and all other subtrees are negative.
Moreover, a tree is negative if its root node is labelled with the number 0, and moreover, some of its subtrees are negative (again, the ones that we obtain
Heuristic algorithm for solving a conjunction of constraintsC.
1. CreateCtreeandCclass.
2. Build a set X− of negative tree variables; add each vi− to X−, where v ∈
Vars(C).
3. Eliminate variables from Ctree (steps 1. and 2. from Fig. 6.11) and try to
create linear loops (step 3. from Fig. 6.11)). For each new variablezthat is created by the rule(.Elim+/−) (or rule(.toLinearLoop)), if we substitute a negative path withz, then addz toX−. Moreover, for each new arithmetic variableλthat is created in the rule(.Elim+/−) (or rule(.toLinearLoop)), if we substitute♦(x) withz, andx∈X−, then add the constraint λ= 0 to
Ctree.
4. Obtain a tree schemaTsby applying the step 4. from Fig. 6.11.
5. Create ∆Ts(Ctree) by iteration, where in each iteration step, whenever we
substitute an atomic expression tae with a variable x, if tae is a negative path, we addxto X−.
6. For each variable x ∈ X−, add the constraint ♦(x) = 0 to ∆Ts(Ctree), and
obtain ∆+Ts/−(Ctree).
7. Continue with items 6. and 7. from Fig. 6.11, using the extended set ∆+Ts/−(Ctree), and obtain a valuationπ.
Figure 6.14: Heuristic algorithm for solving a conjunction of subtyping and arithmetic constraintsC.
by applying the labels in L+), and all others are positive. Thus, we can
force infinite trees to be positive or negative by requiring the appropriate nodes to be labelled with 0. For instance, we must require ♦v−i = 0 and ♦l−(v+i )
= 0, and so on. That is why we modify the elimination and iteration procedures and the procedure for creating linear loops slightly (Fig. 6.14): Whenever we unfold the constraints over trees, or create new tree variables, we need to keep track of which new variables or paths are negative.
Then, we enrich ∆Ts(Ctree) with the constraints ♦(x) = 0, for each neg-
ative variable x ∈ X−. Finally, we continue with the steps six and seven from the algorithm from Fig. 6.11; that is, we attempt to solve the set of constraints ∆Ts(Ctree) enriched with the negativity constraints, using an LP-
Solver. If we obtain a valuationπ, we then create regular trees for the tree variables, by combiningπ with the tree schema.
Theorem 6.6.18 (Soundness of the algorithm from Fig. 6.14) Let C be a conjunction of subtyping and arithmetic constraints and let π be the valuation given by the algorithm described in Fig. 6.14 and letCclasshold. Then, there exists π0 ⊇π withπ0 |=C.
Proof sketch. By Theorem 6.5.21 we have there exists π0 ⊇ π such that π |= Ctree. Moreover, the fact that for each v ∈ Vars(C) holds π0(v+
i ) is
positive and π0(vi−) is negative follows by modifications to the elimination and iteration procedures and the procedure for creating linear loops and by the extension of ∆Ts(Ctree) with the negativity constraints. Then, by
Chapter 7
Prototype Implementation
This chapter describes a prototype implementation of the algorithms pre- sented in this thesis. Section 7.1 describes a memory aware interpreter for FJEU programs. Section 7.1.1 shows how to compile and to use the tool, and Section 7.1.2 describes the analyser module with all its sub-modules. Finally, Section 7.2 describes various programs that we could successfully analyse with the tool.