19
Non-Termination of Affine Loops Kevin Durant, Corina Pasareanu, Willem Visser Stellenbosch University and NASA/CMU

Non-Termination of Affine Loops Kevin Durant, Corina Pasareanu, Willem Visser Stellenbosch University and NASA/CMU

Embed Size (px)

Citation preview

Page 1: Non-Termination of Affine Loops Kevin Durant, Corina Pasareanu, Willem Visser Stellenbosch University and NASA/CMU

Non-Termination of Affine Loops

Kevin Durant, Corina Pasareanu, Willem Visser

Stellenbosch University and NASA/CMU

Page 2: Non-Termination of Affine Loops Kevin Durant, Corina Pasareanu, Willem Visser Stellenbosch University and NASA/CMU

public String preserveTags(String body) {…}

Page 3: Non-Termination of Affine Loops Kevin Durant, Corina Pasareanu, Willem Visser Stellenbosch University and NASA/CMU

Infinite loops are the worst kind of error, since it is input driven and therefore can reappear frequently, in fact infinitely often!

Page 4: Non-Termination of Affine Loops Kevin Durant, Corina Pasareanu, Willem Visser Stellenbosch University and NASA/CMU

Symbolic String Analysis

• (Almost) All Java String operations covered• Mixed Integer and String constraints• Automata and SMT (bitvector) back-ends• Part of Symbolic PathFinder• M.Sc. by Gideon Redelinghuys• Collaborators

– Jaco Geldenhuys (Stellenbosch)

Page 5: Non-Termination of Affine Loops Kevin Durant, Corina Pasareanu, Willem Visser Stellenbosch University and NASA/CMU

Infinite Loop?

while (x > 0) (x,y) = (x+y+2,-x);

Try (2,-3)

Page 6: Non-Termination of Affine Loops Kevin Durant, Corina Pasareanu, Willem Visser Stellenbosch University and NASA/CMU

We only consider affine transformations on loop variables

and simple loop conditions such as x>0 and x>=0

Page 7: Non-Termination of Affine Loops Kevin Durant, Corina Pasareanu, Willem Visser Stellenbosch University and NASA/CMU

x,y are inputs

while (x >= 0) { x := x – y;}

Infinite Loop?

Page 8: Non-Termination of Affine Loops Kevin Durant, Corina Pasareanu, Willem Visser Stellenbosch University and NASA/CMU

x,y are inputs

while (x >= 0) { assert(‘x > x); x := x – y;}

Ranking functions

Page 9: Non-Termination of Affine Loops Kevin Durant, Corina Pasareanu, Willem Visser Stellenbosch University and NASA/CMU

Use ranking functions for non-termination!

Page 10: Non-Termination of Affine Loops Kevin Durant, Corina Pasareanu, Willem Visser Stellenbosch University and NASA/CMU

x,y are inputs

while (x >= 0) { assert(‘x > x); x := x – y;}

Ranking functions

‘x <= x

‘x <= x

‘x <= x…

{c /\ wp(s,‘x <= x)}s

{c /\ wp(s,‘x <= x)}

Page 11: Non-Termination of Affine Loops Kevin Durant, Corina Pasareanu, Willem Visser Stellenbosch University and NASA/CMU

x,y are inputs

while (x >= 0) { assert(‘x > x); x := x – y;}

Inductive?

{x >= 0 /\ wp(x:=x-y,‘x <= x)}x := x - y

{x >= 0/\ wp(x:=x-y,‘x <= x)}

wp(x:=x-y,’x<=x) = {x <= x-y}

{x >= 0 /\ y <= 0}x := x - y

{x >= 0 /\ y <= 0}

Page 12: Non-Termination of Affine Loops Kevin Durant, Corina Pasareanu, Willem Visser Stellenbosch University and NASA/CMU

So how about just…

while (c) { s;}

{c /\ wp(s,!rr)}s

{c /\ wp(s,!rr)}

Page 13: Non-Termination of Affine Loops Kevin Durant, Corina Pasareanu, Willem Visser Stellenbosch University and NASA/CMU

x,y are inputs

while (x >= 0) { assert(‘x > x); x := x + y; y := 1 – y;}

Page 14: Non-Termination of Affine Loops Kevin Durant, Corina Pasareanu, Willem Visser Stellenbosch University and NASA/CMU

x,y are inputs

while (x >= 0) { assert(‘x > x); x := x + y; y := 1 – y;}

{x >= 0 /\ wp(x:=x+y;y:=1-y,‘x <= x)}x := x – y; y := 1 – y;

{x >= 0/\ wp(x:=x+y;y:=1-y,‘x <= x)}

wp(x:=x+y;y:=1-y,’x<=x) = {x <= x+(1-y)}

{x >= 0 /\ y <= 1}x:=x+y;y:=1-y;

{x >= 0 /\ y <= 1}

Page 15: Non-Termination of Affine Loops Kevin Durant, Corina Pasareanu, Willem Visser Stellenbosch University and NASA/CMU

‘x <= x

‘x <= x…

‘x <= x

‘x <= x

‘x <= x…

N

while (c) { s;}

{c /\ wp(sn,!rr)}sn

{c /\ wp(sn,!rr)}

Page 16: Non-Termination of Affine Loops Kevin Durant, Corina Pasareanu, Willem Visser Stellenbosch University and NASA/CMU

while (x0 > 0) { f(x) = Ax+b;}

We conjecture that if there is an infinite loop thenthere exist n such that for all x for which the following is true you will loop infinitely

x0 > 0 /\ f1(x) > 0 /\ … /\ f2n-1(x) > 0 /\ x0 ≤ fn(x) => fn(x) ≤ f2n(x)

Can we derive n from the number of variables in x?

For 1 variable n = 2 For 2 variables n >= 6

For 3 variables there is no n

Page 17: Non-Termination of Affine Loops Kevin Durant, Corina Pasareanu, Willem Visser Stellenbosch University and NASA/CMU

Infinite Loop and no “n”

while (x > 0) { x = 5x+y+z, y = 4y+3z, z = -3y+4z;}

Page 18: Non-Termination of Affine Loops Kevin Durant, Corina Pasareanu, Willem Visser Stellenbosch University and NASA/CMU

Imple

men

tatio

n

JavaPathFinder

Symbolic PathFinderSPF

AffineLoopListener

Model Checker for JavaOpen Source

http://babelfish.arc.nasa.gov/trac/jpf

Symbolic Execution extension for JPF called jpf-symbc

Custom Listener on SPFTries n = 0..6

Page 19: Non-Termination of Affine Loops Kevin Durant, Corina Pasareanu, Willem Visser Stellenbosch University and NASA/CMU

To Do

• Study how many loops can be handled?• Combine with abstraction• Nested Loops?