Combining Widening and Acceleration in Linear Relation

Combining Widening and Acceleration
in Linear Relation Analysis
(work in progress)
Laure Gonnord, Nicolas Halbwachs
VERIMAG
Motivation
Simple loops
Two translation loops
Translations and reset loops
Motivation
Linear Relation Analysis (LRA)
widening:
approximate results,
can be arbitrarily refined by delaying the wideniing
but delaying the widening is expensive
acceleration:
Boigelot/Wolper, Common/Jurski, Finkel/Sutre/Leroux
compute the exact effect of loops
only works for a quite restricted class of programs, high
complexity
L. Gonnord, N. Halbwachs - 2/21
Combining Widening and Acceleration (APRON)
Motivation
Simple loops
Two translation loops
Translations and reset loops
Motivation
Linear Relation Analysis (LRA)
widening:
approximate results,
can be arbitrarily refined by delaying the wideniing
but delaying the widening is expensive
acceleration:
Boigelot/Wolper, Common/Jurski, Finkel/Sutre/Leroux
compute the exact effect of loops
only works for a quite restricted class of programs, high
complexity
L. Gonnord, N. Halbwachs - 2/21
Combining Widening and Acceleration (APRON)
Motivation
Simple loops
Two translation loops
Translations and reset loops
A motivating example: the gaz burner
Continuous behaviour
t := 0
` := 0
x := 0
20
leaking
ṫ = 1
`˙ = 1
ẋ = 1
x ≤ 10
not leaking
x := 0
ṫ = 1
`˙ = 0
ẋ = 1
x ≥ 50
x := 0
`
10
50
L. Gonnord, N. Halbwachs - 3/21
60
70
t
Combining Widening and Acceleration (APRON)
Motivation
Simple loops
Two translation loops
Translations and reset loops
The gaz burner (cont.)
x := 0
Discretizing
t := 0
x ≤ 9?
` := 0
t ++
x := 0
` ++
x ++
L
N
x ≥ 50?
x := 0
t ++
x ++
`
t
L. Gonnord, N. Halbwachs - 4/21
Combining Widening and Acceleration (APRON)
Motivation
Simple loops
Two translation loops
Translations and reset loops
The gaz burner (end.)
We want to replace the loops ...
t := 0
` := 0
x := 0
L
x ≥ 50?
x := 0
τ1⊗
N’
τ2⊗
L’
N
x := 0
L. Gonnord, N. Halbwachs - 5/21
Combining Widening and Acceleration (APRON)
Motivation
Simple loops
Two translation loops
Translations and reset loops
Simple loops
We want to caracterise P = τ ∗ (P0 ), where :
τ (x) = if Ax ≤ B then Cx + D else x
with (A, B) “guard” and (C , D) “action”
x ∈ P ⇔ ∃i ∈ N, ∃x0 ∈ P0 , x = τ i (x0 )
P
i.e., if we define the sequence (xk ) by xi = C i x0 + ij=0 C j D :
x ∈ τ ∗ (x0 ) ⇔ ∃i ∈ N, x = xi and ∀j ∈ [0, i − 1], Axj ≤ B
L. Gonnord, N. Halbwachs - 6/21
Combining Widening and Acceleration (APRON)
Motivation
Simple loops
Two translation loops
Translations and reset loops
Some simple cases
Computing C k is too expensive
[Leroux02] : the linear functions λx.CX + D with
{C k , k ∈ N} finite are effectively Presburger-definable.
Simplest case: C = Id (“translation”)
Some cases hwre C 2 = C (incrementation / assignment to
constant).
L. Gonnord, N. Halbwachs - 7/21
Combining Widening and Acceleration (APRON)
Motivation
Simple loops
Two translation loops
Translations and reset loops
Single translation loop
τ (x) = if Ax ≤ B then x + D else x
(obvious) Proposition If C = Id, then x ∈ τ ∗ (P0 ) iff
∃i ∈ N, ∃x0 ∈ P0 , Ax0 ≤ B, A(x − D) ≤ B, x = x0 + iD
Abstract acceleration
G
τ ⊗ (P0 ) = {x | ∃i ∈ Q, ∃x0 ∈ P0 ,
Ax0 ≤ B, A(x − D) ≤ B, x = x0 + iD}
Computation
τ ⊗ (P0 ) = ((P0 ∩ (Ax ≤ B)) % D) ∩ (A(x − D) ≤ B)
L. Gonnord, N. Halbwachs - 8/21
Combining Widening and Acceleration (APRON)
Motivation
Simple loops
Two translation loops
Translations and reset loops
Single translation loop
τ (x) = if Ax ≤ B then x + D else x
(obvious) Proposition If C = Id, then x ∈ τ ∗ (P0 ) iff
∃i ∈ N, ∃x0 ∈ P0 , Ax0 ≤ B, A(x − D) ≤ B, x = x0 + iD
Abstract acceleration
G
τ ⊗ (P0 ) = {x | ∃i ∈ Q, ∃x0 ∈ P0 ,
Ax0 ≤ B, A(x − D) ≤ B, x = x0 + iD}
Computation
τ ⊗ (P0 ) = ((P0 ∩ (Ax ≤ B)) % D) ∩ (A(x − D) ≤ B)
L. Gonnord, N. Halbwachs - 8/21
Combining Widening and Acceleration (APRON)
Motivation
Simple loops
Two translation loops
Translations and reset loops
Ex.: gaz burner
x := 0
t := 0
x ≤ 9?
` := 0
t ++
x := 0
` ++
x ++
20
L
N
x ≥ 50?
x := 0
t ++
x ++
`
10
50
L. Gonnord, N. Halbwachs - 9/21
60
70
t
Combining Widening and Acceleration (APRON)
Motivation
Simple loops
Two translation loops
Translations and reset loops
Two loops - First remarks
(τ1 + τ2 )∗ (P0 ) is not necessarily convex :
$x_0$
L. Gonnord, N. Halbwachs - 10/21
Combining Widening and Acceleration (APRON)
Motivation
Simple loops
Two translation loops
Translations and reset loops
Two loops - First remarks
There can be quite complex oscillations
$x_0$
L. Gonnord, N. Halbwachs - 11/21
Combining Widening and Acceleration (APRON)
Motivation
Simple loops
Two translation loops
Translations and reset loops
Several loops: partitionning
g1 g2
g1 g2
g1 g2
g1 → a1
g2 → a2
g1 g2
p(a1 )(g1 )
p(a1 )( g2 )
→ a1
g1 g2
p(a1 )(g1 ) p(a2 )(g2 )
p(a1 )(g2 ) p(a2 )(g1 )
→ a1
→ a2
g1 g2
p(a2 )(g2 )
p(a2 )( g1 )
→ a2
(at least conceptually)
L. Gonnord, N. Halbwachs - 12/21
Combining Widening and Acceleration (APRON)
Motivation
Simple loops
Two translation loops
Translations and reset loops
Two simple translation loops – results
Simple translation loops: simple guards g = ax ≤ b
τi (x) = if gi then x + Di else x , i = 1, 2
We know how to abstractly accelerate two simple loops as long as
both guards are satisfied (not completely obvious)
Result: if P0 ⊆ g1 ∩ g2 then
(τ1 + τ2 )⊗ (P0 ) ∩ g1 ∩ g2 = (P0 % {D1 , D2 }) ∩ g1 ∩ g2
L. Gonnord, N. Halbwachs - 13/21
Combining Widening and Acceleration (APRON)
Motivation
Simple loops
Two translation loops
Translations and reset loops
Old Cousot&Halbwachs78 example
i:=j:=0;
while i<= 100 do
1 if ? then i:=i+2
else i:=i+2; j:=j+1
fi
od
i := j := 0
i ≤ 100 →
i := i + 2
i ≤ 100 →
i := i + 2; j := j + 1
Immediate result at 1:
(0, 0) % {(2, 0), (2, 1)} ∩ (i ≤ 100)
= 0 ≤ 2j ≤ i ≤ 100
L. Gonnord, N. Halbwachs - 14/21
Combining Widening and Acceleration (APRON)
Motivation
Simple loops
Two translation loops
Translations and reset loops
Two loops with reset (or constant assignments)
X = (Y , Z )
g2 →
X := X + B2
L. Gonnord, N. Halbwachs - 15/21
P0
P
g1 →
Y := Y + B1 ; Z := 0
Combining Widening and Acceleration (APRON)
Motivation
Simple loops
Two translation loops
Translations and reset loops
Unconditional simple reset
{X0 }
X = (Y , Z )
g2 → X := X + B2
P
Let B20 = [Z ; = 0]B2 . In the plane (B2 , B20 ):
true → Z := 0
g2 (X )
B2
B20
X0
P = {X0 } % {B2 , B20 } ∩ g2
L. Gonnord, N. Halbwachs - 16/21
Combining Widening and Acceleration (APRON)
Motivation
Simple loops
Two translation loops
Translations and reset loops
Remark:
1
3
The exact set is not semi-linear
L. Gonnord, N. Halbwachs - 17/21
7
Combining Widening and Acceleration (APRON)
Motivation
Simple loops
Two translation loops
Translations and reset loops
Unconditional translation/reset
{X0 }
g2 →
X := X + B2
P
true →
Y := Y + B1 ; Z := 0
Z
Y
B2
B1
x0
B20
P = P0 % {B1 , B2 , kmax B20 + B1 } ∩ g2
L. Gonnord, N. Halbwachs - 18/21
Combining Widening and Acceleration (APRON)
Motivation
Simple loops
Two translation loops
Translations and reset loops
Only works if g2 = Z ≤ C (modulo variable change)
Z
Y
B2
B1
x0
B20
L. Gonnord, N. Halbwachs - 19/21
Combining Widening and Acceleration (APRON)
Motivation
Simple loops
Two translation loops
Translations and reset loops
An other (more difficult) version of the gaz burner
t=`=u=v =0
v ≤ 9?
t ++
`++
u++
v ++
τ1
u ≤ 59?
t ++
τ2
u++
u = 60?
τ3 t + +
u=v =0
Let X = (t, `, u, v ), Z = {u, v }. X0 = (0, 0, 0, 0).
L. Gonnord, N. Halbwachs - 20/21
Combining Widening and Acceleration (APRON)
Motivation
Simple loops
Two translation loops
Translations and reset loops
t=`=u=v =0
v ≤ 9?
t ++
`++
u++
v ++
τ1
u ≤ 59?
t ++
u++
τ2
u = 60?
τ3 t + +
u=v =0
We compute
F1 = (τ1 + τ2 )∗ (X0 ) = {` = v , t = u, 0 ≤ ` ≤ 10, ` ≤ t ≤ 60}
(two simple translation loops).
Then, τ3 (F1 ) = {u = v = 0, t = 60, 0 ≤ ` ≤ 10}, thus
D3 + k1max D1Y = (0, 60, 0, 0) and D3 + k2max D2Y = (0, 60, 10, 0)
And we finally get :
F (X0 ) = {` ≥ v , u ≤ 60, 0 ≤ v ≤ 10, u ≥ v , u + 6` ≤ t + 6y }
whose projecton onto {t, `} gives {t + 50 ≥ 6`, ` ≥ 0, t ≥ `}.
L. Gonnord, N. Halbwachs - 21/21
Combining Widening and Acceleration (APRON)