• No results found

6.5 Solving a system of constraints

6.5.2 Computation of ∆ Ts (C)

In the previous section we described the set ∆Ts(C) and proved that its

satisfiability implies the satisfiability ofC. The natural question that arises is how to compute ∆Ts(C). ComputingAC[Ts] is simple, the challenge is the

computation of ΓTs(T C). Adding constraints to the set for each pathw∈ L∗

according to the definition is clearly infeasible since there are infinitely many paths. However, we can calculate the desired set by iteration: we build a set

Γi Ts(T C) ΓiTs(T C) = S tevte0∈T C{tew[Ts]vtew0 [Ts]|w∈ L∗,|w| ≤i} T Ci Ts treeConstrs(T C) = {l(te)[Ts]vl(te0)[Ts]|tevte0∈ T C, l∈ L} T C0 Ts = T C[Ts] T Ci+1 Ts = T C i Ts∪treeConstrs(T CiTs) T C∞ Ts = S i≥0T C i Ts w[te] [te] = te w l[te] = w[l(te)] Figure 6.8: ΓiTs(T C) and T Ci Ts.

ΓiTs(T C) iteratively. In thei-th step of the iteration the set contains exactly the constraints corresponding to the pathswwith|w| ≤i. We prove that the iteration terminates, i.e. that there is an indexj with ΓjTs(T C) = Γj+1Ts (T C) and that this set contains all the constraints in ΓTs(T C).

The sets ΓiTs(T C) are useful for proving the soundness of the iteration and for understanding how it works. However, actually building the sets in each iteration would be inefficient. Instead, we build a set of tree constraintsT Ci

Ts

iteratively (Fig. 6.8), by adding new constraints in each step, so that the following invariant holds: for all i, Γ0Ts(T Ci

Ts) = ΓiTs(T C). In the following,

we prove the soundness of the iteration: ΓTs(T C) = Γ0Ts(T C ∞

Ts) that follows

directly from the invariant. For the proof it is convenient to define w[te] : TExp (Fig. 6.8) to be able to describe the constraints in T Ci for some iin

terms of the constraints in T C.

Lemma 6.5.8 Let T C be a set of constraints andtc∈ T C andTs be a tree schema andte∈TExp and w∈ L∗. Then:

1. tew[Ts] = ¯w[te][Ts]

2. T CiTs={w¯[te][Ts]≤w¯[te0][Ts]|tevte0 ∈ T C, w∈ L∗,|w| ≤i}

3. For all iholds Γ0Ts(T Ci

Ts) = ΓiTs(T C). Proof.

1. By induction on w. 2. By induction on i.

Case i→i+ 1

T Ci+1Ts = T Ci

Ts∪treeConstrs(T CiTs)

=I.H. {w¯[te][Ts]≤w¯[te0][Ts]|tevte0 ∈ T C,|w| ≤i} ∪

{lw¯[te][Ts]≤lw¯[te0][Ts]|tevte0 ∈ T C,|w| ≤i} = {w¯[te][Ts]≤w¯[te0][Ts]| |w| ≤i+ 1}

3. We show

Γ0Ts(T CiTs) = ΓiTs(T C)

{w¯[te][Ts]≤w¯[te0][Ts]} =2. {tew[Ts]≤te0w[Ts]}

for eachtevte0∈ T C and w∈ L∗ with|w| ≤i, and that follows by 1.

2

Corollary 6.5.9 (Soundness of iteration) LetT Cbe a set of constraints andTs be a tree schema. Then: ΓTs(T C) = Γ0Ts(T C

∞ Ts). Proof. Follows from Lemma 6.5.8, item 3., since ΓTs(T C) =

S

i≥0ΓiTs(T C).

2

Next, we prove termination of the iteration. The proof consists of two parts. First we notice that, sinceT CiTs⊆ T Ci+1Ts for alli, if there exists an indexn0 with treeConstrs(T CnTs0) ⊆ T CTsn0, then T CnTs0 =T CnTs0+1 and for all

i≥n0 T CiTs=T C n0

Ts. The second part of the proof consists in showing that

such an index indeed exists for this sequence. It follows from the soundness of the iteration and from the fact that the set ΓTs(T C) is finite.

Lemma 6.5.10 (Termination of iteration) LetT Cbe a set of constraints andTs be a tree schema. Then:

1. If there is n0 with treeConstrs(T CnTs0) ⊆ T CTsn0 then ∀i ≥ n0.T CiTs =

T Cn0

Ts.

2. There is n0 withT CnTs0 =T CTsn0+1 and T C∞Ts=T CnTs0. Proof.

1. By induction on i. 2. Let us assume T Ci

Ts ( T Ci+1Ts for all i. Then, T C ∞

Ts is infinite and

Γ0Ts(T C∞Ts) = ΓTs(T C) is infinite as well, but this is a contradiction to

Lemma 6.5.3. Therefore, there existsn0 with T CnTs0 =T C n0+1

Ts . Then,

T C∞Ts=T Cn0

Ts follows by 1.

Corollary 6.5.11 (Computation of ΓTs(T C)) Let T C be a set of con- straints and Ts be a tree schema and n0 ∈ N with T CnTs0 =T C

n0+1

Ts . Then

ΓTs(T C) = Γ0Ts(T C n0

Ts).

Proof. Follows by Corollary 6.5.9 and Lemma 6.5.10. 2

Example 6.5.12 (Computation of ΓTs(T C)) LetTsandLbe defined like in Example 6.5.2 and T C be defined like in Example 6.5.4. Then, we can build ΓTs(T C) as follows: T C0 Ts = {x2vx2, x1vx1} T C1Ts = {x1vx1, x2vx2} SinceT C0 Ts=T C1Ts, it followsT C ∞ Ts=T C1Ts. Moreover ΓTs(T C) = Γ0Ts({x1 vx1, x2 vx2}) = {λ1≤λ1, λ2 ≤λ2}