![Page 1: Non-Termination of Affine Loops Kevin Durant, Corina Pasareanu, Willem Visser Stellenbosch University and NASA/CMU](https://reader036.vdocuments.mx/reader036/viewer/2022062519/5697bfd01a28abf838caabb3/html5/thumbnails/1.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062519/5697bfd01a28abf838caabb3/html5/thumbnails/2.jpg)
public String preserveTags(String body) {…}
![Page 3: Non-Termination of Affine Loops Kevin Durant, Corina Pasareanu, Willem Visser Stellenbosch University and NASA/CMU](https://reader036.vdocuments.mx/reader036/viewer/2022062519/5697bfd01a28abf838caabb3/html5/thumbnails/3.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062519/5697bfd01a28abf838caabb3/html5/thumbnails/4.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062519/5697bfd01a28abf838caabb3/html5/thumbnails/5.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062519/5697bfd01a28abf838caabb3/html5/thumbnails/6.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062519/5697bfd01a28abf838caabb3/html5/thumbnails/7.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062519/5697bfd01a28abf838caabb3/html5/thumbnails/8.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062519/5697bfd01a28abf838caabb3/html5/thumbnails/9.jpg)
Use ranking functions for non-termination!
![Page 10: Non-Termination of Affine Loops Kevin Durant, Corina Pasareanu, Willem Visser Stellenbosch University and NASA/CMU](https://reader036.vdocuments.mx/reader036/viewer/2022062519/5697bfd01a28abf838caabb3/html5/thumbnails/10.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062519/5697bfd01a28abf838caabb3/html5/thumbnails/11.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062519/5697bfd01a28abf838caabb3/html5/thumbnails/12.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062519/5697bfd01a28abf838caabb3/html5/thumbnails/13.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062519/5697bfd01a28abf838caabb3/html5/thumbnails/14.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062519/5697bfd01a28abf838caabb3/html5/thumbnails/15.jpg)
‘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](https://reader036.vdocuments.mx/reader036/viewer/2022062519/5697bfd01a28abf838caabb3/html5/thumbnails/16.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062519/5697bfd01a28abf838caabb3/html5/thumbnails/17.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062519/5697bfd01a28abf838caabb3/html5/thumbnails/18.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022062519/5697bfd01a28abf838caabb3/html5/thumbnails/19.jpg)
To Do
• Study how many loops can be handled?• Combine with abstraction• Nested Loops?