Simple Programs that are Hard to Analyze

advertisement
Simple Programs that are Hard to Analyze
Amir M. Ben-Amram
Neil Jones Workshop
June 2014
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
1 / 14
JACM, 1977
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
2 / 14
JACM, 1978
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
3 / 14
JACM, 1977: Main Contribution
Even Simple Programs are Hard to Analyze
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
4 / 14
JACM, 1977: Main Contribution
Even Simple Programs are Hard to Analyze
1
A class of simple programs
Finite-memory programs
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
4 / 14
JACM, 1977: Main Contribution
Even Simple Programs are Hard to Analyze
1
A class of simple programs
Finite-memory programs
2
Certain decision problems regarding programs
Termination: Does the computation always terminate?
Reachability: Does it ever reach a certain state?
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
4 / 14
JACM, 1977: Main Contribution
Even Simple Programs are Hard to Analyze
1
A class of simple programs
Finite-memory programs
2
Certain decision problems regarding programs
Termination: Does the computation always terminate?
Reachability: Does it ever reach a certain state?
3
Classification of the computational complexity of the problems
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
4 / 14
JACM, 1977: Main Contribution
Even Simple Programs are Hard to Analyze
1
A class of simple programs
Finite-memory programs
2
Certain decision problems regarding programs
Termination: Does the computation always terminate?
Reachability: Does it ever reach a certain state?
3
Classification of the computational complexity of the problems
This talk
Some interesting program classes and hardness results
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
4 / 14
Scale of Computational Hardness
R
PSPACE (polynomial space)-complete
NP-complete
PTIME (polynomial time)
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
5 / 14
Scale of Computational Hardness
UN
DE
CI
DA
B
LE
R
PSPACE (polynomial space)-complete
NP-complete
PTIME (polynomial time)
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
5 / 14
Scale of Computational Hardness
UN
DE
CI
DA
B
LE
R
DE
C
BU IDAB
TH
L
AR E,
D
PSPACE (polynomial space)-complete
NP-complete
PTIME (polynomial time)
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
5 / 14
Scale of Computational Hardness
UN
DE
CI
Ope
DA
B
np
rob
lem
s
LE
R
DE
C
BU IDAB
TH
L
AR E,
D
PSPACE (polynomial space)-complete
NP-complete
PTIME (polynomial time)
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
5 / 14
Example 1: Finite Memory Programs
1:
2:
3:
4:
X := ’a ’
Y := ’b ’
if X = Y goto 1
end
Programs with BASIC structure (assignments/tests/goto)
A finite set of variables.
Each variable holds one character.
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
6 / 14
Example 1: Finite Memory Programs
1:
2:
3:
4:
X := ’a ’
Y := ’b ’
if X = Y goto 1
end
Programs with BASIC structure (assignments/tests/goto)
A finite set of variables.
Each variable holds one character.
Such a program has a finite state-space so exhaustive search can
answer our questions (in polynomial space).
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
6 / 14
Example 1: Finite Memory Programs
1:
2:
3:
4:
X := ’a ’
Y := ’b ’
if X = Y goto 1
end
Programs with BASIC structure (assignments/tests/goto)
A finite set of variables.
Each variable holds one character.
Such a program has a finite state-space so exhaustive search can
answer our questions (in polynomial space).
Jones and Muchnick’s result: they are PSPACE-complete—as hard as
they could get.
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
6 / 14
Example 2: Counter Programs
1:
2:
3:
4:
5:
X := 0
Y := X +1
if X = Y goto 1
Y := Y -1
end
Values are unrestricted integers and subject to increment, decrement
and test.
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
7 / 14
Example 2: Counter Programs
1:
2:
3:
4:
5:
X := 0
Y := X +1
if X = Y goto 1
Y := Y -1
end
Values are unrestricted integers and subject to increment, decrement
and test.
This language is Turing-complete.
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
7 / 14
Example 2: Counter Programs
1:
2:
3:
4:
5:
X := 0
Y := X +1
if X = Y goto 1
Y := Y -1
end
Values are unrestricted integers and subject to increment, decrement
and test.
This language is Turing-complete.
These are not simple programs.
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
7 / 14
Example 3: Linear Loops
while ( x >=0 && y >=0 && 2* z + w >= 3 && ... )
{
x := x - y ;
y := y -1;
...
}
Just one loop with linear expressions in the assignments and the loop
condition.
Matrix notation:
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
8 / 14
Example 3: Linear Loops
while ( x >=0 && y >=0 && 2* z + w >= 3 && ... )
{
x := x - y ;
y := y -1;
...
}
Just one loop with linear expressions in the assignments and the loop
condition.
Matrix notation:
while A~x ≤ c:
~x ← B~x + d
~x is the state vector
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
8 / 14
Example 3: Linear Loops
while ( x >=0 && y >=0 && 2* z + w >= 3 && ... )
{
x := x - y ;
y := y -1;
...
}
Just one loop with linear expressions in the assignments and the loop
condition.
Matrix notation:
while A~x ≤ c:
~x ← B~x + d
~x is the state vector
Problem: termination (for all initial states)
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
8 / 14
Example 3: Linear Loops: results
Decidability of the termination problem is unknown.
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
9 / 14
Example 3: Linear Loops: results
Decidability of the termination problem is unknown.
B., Genaim and Masud (2012) considered certain extended forms
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
9 / 14
Example 3: Linear Loops: results
Decidability of the termination problem is unknown.
B., Genaim and Masud (2012) considered certain extended forms
1
Include the assignment form Y := isPositive(X) where
0
x≤0
isPositive(x) =
1
x>0
Termination is undecidable.
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
9 / 14
Example 3: Linear Loops: results
Decidability of the termination problem is unknown.
B., Genaim and Masud (2012) considered certain extended forms
1
Include the assignment form Y := isPositive(X) where
0
x≤0
isPositive(x) =
1
x>0
Termination is undecidable.
Note: if we could compute products (e.g., isPositive(X ) ? Y ) we
could simulate branches quite easily.
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
9 / 14
Example 3: Linear Loops: results
Decidability of the termination problem is unknown.
B., Genaim and Masud (2012) considered certain extended forms
1
Include the assignment form Y := isPositive(X) where
0
x≤0
isPositive(x) =
1
x>0
Termination is undecidable.
Note: if we could compute products (e.g., isPositive(X ) ? Y ) we
could simulate branches quite easily.
2
Termination is also undecidable for loops with a single test:
while A~x ≤ c:
if x1 > 0 then ~x ← B1~x
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
else ~x ← B2~x
June 2014
9 / 14
Example 3: Linear Loops: Variations
The point-to-point problem
~x ← a;
while (~x 6= b) ~x ← A~x
Starts at a given point, a
Has to reach point b to terminate
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
10 / 14
Example 3: Linear Loops: Variations
The point-to-point problem
~x ← a;
while (~x 6= b) ~x ← A~x
Starts at a given point, a
Has to reach point b to terminate
Solved in polynomial time (Kannan and Lipton, 1986).
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
10 / 14
Example 3: Linear Loops: Variations
The point-to-point problem
~x ← a;
while (~x 6= b) ~x ← A~x
Starts at a given point, a
Has to reach point b to terminate
Solved in polynomial time (Kannan and Lipton, 1986).
The point-to-hyperplane problem
~x ← a;
while (b · ~x 6= 0) ~x ← A~x
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
10 / 14
Example 3: Linear Loops: Variations
The point-to-point problem
~x ← a;
while (~x 6= b) ~x ← A~x
Starts at a given point, a
Has to reach point b to terminate
Solved in polynomial time (Kannan and Lipton, 1986).
The point-to-hyperplane problem
~x ← a;
while (b · ~x 6= 0) ~x ← A~x
NP-hard (Blondel and Portier, 2002).
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
10 / 14
Example 3: Linear Loops: Variations
The point-to-point problem
~x ← a;
while (~x 6= b) ~x ← A~x
Starts at a given point, a
Has to reach point b to terminate
Solved in polynomial time (Kannan and Lipton, 1986).
The point-to-hyperplane problem
~x ← a;
while (b · ~x 6= 0) ~x ← A~x
NP-hard (Blondel and Portier, 2002).
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
10 / 14
Example 3: Linear Loops: Variations
The point-to-point problem
~x ← a;
while (~x 6= b) ~x ← A~x
Starts at a given point, a
Has to reach point b to terminate
Solved in polynomial time (Kannan and Lipton, 1986).
The point-to-hyperplane problem
~x ← a;
while (b · ~x 6= 0) ~x ← A~x
NP-hard (Blondel and Portier, 2002).
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
10 / 14
Example 3: Linear Loops: Variations
The point-to-point problem
~x ← a;
while (~x 6= b) ~x ← A~x
Starts at a given point, a
Has to reach point b to terminate
Solved in polynomial time (Kannan and Lipton, 1986).
The point-to-hyperplane problem
~x ← a;
while (b · ~x 6= 0) ~x ← A~x
NP-hard (Blondel and Portier, 2002).
Decidability is open!
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
10 / 14
Example 3: Linear Loops: Further Variations
Cortier (2002): variables hold natural numbers.
Transformation ~x ← A1~x + b1 is iterated an unknown number of times,
and then another one ~x ← A2~x + b2 is iterated.
The problem: point-to-point reachability.
Result: decidable.
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
11 / 14
Example 3: Linear Loops: Further Variations
Cortier (2002): variables hold natural numbers.
Transformation ~x ← A1~x + b1 is iterated an unknown number of times,
and then another one ~x ← A2~x + b2 is iterated.
The problem: point-to-point reachability.
Result: decidable.
A similar problem, where the program consists of p stages (stage k
iterating ~x ← Ak ~x + bk ) is undecidable for p large enough.
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
11 / 14
Example 4: The Budach Mouse
A problem posed by Lothar Budach at FCT 1979.
The mouse (Mus Automaticus Budachi) is a simple finite-state machine,
which wanders about the first positive octant of the integer grid.
Its program is a string over {E , N}, through which is cycles indefinitely.
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
12 / 14
Example 4: The Budach Mouse
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
13 / 14
Example 4: The Budach Mouse
Decision problem
Will the mouse ever hit the line x = y
when in step k of the cycle?
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
13 / 14
Example 4: The Budach Mouse
Decision problem
Will the mouse ever hit the line x = y
when in step k of the cycle?
OPEN
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
13 / 14
Conclusion
Neil was right!
Congratulations, Neil, on a highly-deserved recognition,
And thanks for twenty years of inspiration
Amir M. Ben-Amram
Simple Programs that are hard to Analyze
June 2014
14 / 14
Download