Safety Problems are NP-complete for Flat Integer Programs with - - PowerPoint PPT Presentation
Safety Problems are NP-complete for Flat Integer Programs with - - PowerPoint PPT Presentation
Safety Problems are NP-complete for Flat Integer Programs with Octagonal Loops Marius Bozga, Radu Iosif (Verimag/CNRS, France) Filip Konecny (EPFL, Switzerland) Motivation Infinite state systems are, in general, undecidable Few
Motivation
- Infinite state systems are, in general, undecidable
- Few complexity results for the decidable cases:
➡
VAS coverage (EXPSPACE-complete) [Rackoff 1978]
➡
inequivalence of reversal-bounded CM (NP-complete) [Ibarra, Gurari 1981]
➡
gap-order constraints (PSPACE-complete) [Bozzelli, Pinchinat 2012]
- Efficient algorithm for flat integer programs with
difference bounds and octagonal loops [BIK’10]
➡
worst case EXPTIME, yet good average performance
- NP-completness explains the behavior of our algorithm
➡
educated guessing may solve NP-complete problems efficiently
Flat Integer Programs
int y = y0; int n = 2*m - x; while (x < n) { if (x < m) { x ++; y ++; } else { x ++; y --; }} assert(y == y0);
Flat Integer Programs
int y = y0; int n = 2*m - x; while (x < n) { if (x < m) { x ++; y ++; } else { x ++; y --; }} assert(y == y0);
x y y0 x0 m n
Flat Integer Programs
int y = y0; int n = 2*m - x; while (x < n) { if (x < m) { x ++; y ++; } else { x ++; y --; }} assert(y == y0);
Flat Integer Programs
int y = y0; int n = 2*m - x; while (x < n) { if (x < m) { x ++; y ++; } else { x ++; y --; }} assert(y == y0);
y’=y0 n’=2*m-x x < n x < m x’=x+1 y’=y+1 x < n x ≥ m x’=x+1 y’=y-1 y ≠ y0
Flat Integer Programs
int y = y0; int n = 2*m - x; while (x < n) { if (x < m) { x ++; y ++; } else { x ++; y --; }} assert(y == y0);
y’=y0 n’=2*m-x x < n x < m x’=x+1 y’=y+1 x < n x ≥ m x’=x+1 y’=y-1 y ≠ y0
{
x1-x0=y1-y0=m-x0
Flat Integer Programs
int y = y0; int n = 2*m - x; while (x < n) { if (x < m) { x ++; y ++; } else { x ++; y --; }} assert(y == y0);
y’=y0 n’=2*m-x x < n x < m x’=x+1 y’=y+1 x < n x ≥ m x’=x+1 y’=y-1 y ≠ y0
{
x1-x0=y1-y0=m-x0
{
x2-x1=y1-y2=n-m
Flat Integer Programs
int y = y0; int n = 2*m - x; while (x < n) { if (x < m) { x ++; y ++; } else { x ++; y --; }} assert(y == y0);
y’=y0 n’=2*m-x x < n x < m x’=x+1 y’=y+1 x < n x ≥ m x’=x+1 y’=y-1 y ≠ y0
{
x1-x0=y1-y0=m-x0
{
x2-x1=y1-y2=n-m
{
y1-y0=y1-y2
Flat Integer Programs
int y = y0; int n = 2*m - x; while (x < n) { if (x < m) { x ++; y ++; } else { x ++; y --; }} assert(y == y0);
y’=y0 n’=2*m-x x < n x < m x’=x+1 y’=y+1 x < n x ≥ m x’=x+1 y’=y-1 y ≠ y0
{
x1-x0=y1-y0=m-x0
{
x2-x1=y1-y2=n-m
{
y1-y0=y1-y2 y0=y2
Flat Integer Programs
- Reachability is decidable if the relations labeling the
loops belong to certain classes of linear inequalities
- Difference bounds constraints:
3 ≤ x ≤ 5 /\ 1 ≤ y ≤ 3 /\ 2 ≤ x - y ≤ 4
Flat Integer Programs
- Reachability is decidable if the relations labeling the
loops belong to certain classes of linear inequalities
- Difference bounds constraints:
3 ≤ x ≤ 5 /\ 1 ≤ y ≤ 3 /\ 2 ≤ x - y ≤ 4 x y 1 3 5 3
Flat Integer Programs
- Reachability is decidable if the relations labeling the
loops belong to certain classes of linear inequalities
- Octagonal constraints:
4 ≤ x ≤ 6 /\ 1 ≤ y ≤ 3 /\ 0 ≤ x - y ≤ 5 /\ 5 ≤ x + y ≤ 7
Flat Integer Programs
- Reachability is decidable if the relations labeling the
loops belong to certain classes of linear inequalities
- Octagonal constraints:
4 ≤ x ≤ 6 /\ 1 ≤ y ≤ 3 /\ 0 ≤ x - y ≤ 5 /\ 5 ≤ x + y ≤ 7 x y 1 4 6 3 5 7
Difference Bounds Relations
x2 x2′ x1 x1′
Difference Bounds Relations
x2 x2′ x1 x1′
1
x1 - x1′ ≤ 1
Difference Bounds Relations
x2 x2′ x1 x1′
1
x1 - x1′ ≤ 1
- 1
x1 - x2′ ≤ -1
Difference Bounds Relations
x2 x2′ x1 x1′
1
x1 - x1′ ≤ 1
- 1
x1 - x2′ ≤ -1
- 2
x2 - x1′ ≤ -2
Difference Bounds Relations
x2 x2′ x1 x1′
1
x1 - x1′ ≤ 1
- 1
x1 - x2′ ≤ -1
- 2
x2 - x1′ ≤ -2
2
x2 - x2′ ≤ 2
Difference Bounds Relations
x2 x2′ x1 x1′
1
x1 - x1′ ≤ 1
- 1
x1 - x2′ ≤ -1
- 2
x2 - x1′ ≤ -2
2
x2 - x2′ ≤ 2 x1 x2 x1′ x2′ x1
∞ 1
- 1
x2
∞
- 2
2
x1′
∞ ∞ ∞
x2′
∞ ∞ ∞
Difference Bounds Relations
x2 x1 x2′ x1′
1
- 1
- 2
2
Difference Bounds Relations
x2 x1 x2′ x1′
1
- 1
- 2
2
x2′′ x1′′
1
- 1
- 2
2
Difference Bounds Relations
x2 x1 x2′ x1′
1
- 1
- 2
2
x2′′ x1′′
1
- 1
- 2
2
x2′′′ x1′′′
1
- 1
- 2
2
Difference Bounds Relations
x2 x1 x2′ x1′
1
- 1
- 2
2
x2′′ x1′′
1
- 1
- 2
2
x2′′′ x1′′′
1
- 1
- 2
2
x2iv x1iv
1
- 1
- 2
2
Difference Bounds Relations
x2 x1 x2′ x1′
1
- 1
- 2
2
x2′′ x1′′
1
- 1
- 2
2
x2′′′ x1′′′
1
- 1
- 2
2
x2iv x1iv
1
- 1
- 2
2
x1 - x1iv ≤ -6
Difference Bounds Relations
x2 x1 x2′ x1′
1
- 1
- 2
2
x2′′ x1′′
1
- 1
- 2
2
x2′′′ x1′′′
1
- 1
- 2
2
x2iv x1iv
1
- 1
- 2
2
x1 - x1iv ≤ -6 x1 - x2iv ≤ -2
Difference Bounds Relations
x2 x1 x2′ x1′
1
- 1
- 2
2
x2′′ x1′′
1
- 1
- 2
2
x2′′′ x1′′′
1
- 1
- 2
2
x2iv x1iv
1
- 1
- 2
2
x1 - x1iv ≤ -6 x1 - x2iv ≤ -2 x2 - x1iv ≤ -4
Difference Bounds Relations
x2 x1 x2′ x1′
1
- 1
- 2
2
x2′′ x1′′
1
- 1
- 2
2
x2′′′ x1′′′
1
- 1
- 2
2
x2iv x1iv
1
- 1
- 2
2
x1 - x1iv ≤ -6 x1 - x2iv ≤ -2 x2 - x1iv ≤ -4 x2 - x2iv ≤ -6
Difference Bounds Relations
x2 x1 x2′ x1′
1
- 1
- 2
2
x2′′ x1′′
1
- 1
- 2
2
x2′′′ x1′′′
1
- 1
- 2
2
x2iv x1iv
1
- 1
- 2
2
x1 - x1iv ≤ -6 x1 - x2iv ≤ -2 x2 - x1iv ≤ -4 x2 - x2iv ≤ -6
Difference Bounds Relations
x2 x1 x2′ x1′
1
- 1
- 2
2
x2′′ x1′′
1
- 1
- 2
2
x2′′′ x1′′′
1
- 1
- 2
2
x2iv x1iv
1
- 1
- 2
2
x1 - x1iv ≤ -6 x1 - x2iv ≤ -2 x2 - x1iv ≤ -4 x2 - x2iv ≤ -6
- The n-th power of a DB relation is again a DB relation:
➡ the class of DB has quantifier elimination
- We are interested in computing minimal weight paths
- The graph for the n-th power has (n+1)×(#vars) nodes
- The paths in the graph are regular
Difference Bounds Relations
x1 x2 x3 x4 x5 x6 x7 x1′ x2′ x3′ x4′ x5′ x6′ x7′ x1 - x2′ ≤ 0 x2 - x3′ ≤ 0 x3′ - x2 ≤ 0 x4′ - x5 ≤ 0 x5′ - x6 ≤ 0 x6′ - x6 ≤ 1 x6′ - x7 ≤ 0 x7 - x7′ ≤ 1 x7′ - x5 ≤ 0 x5 - x1′ ≤ -1
Difference Bounds Relations
x1 x2 x3 x4 x5 x6 x7 x1′ x2′ x3′ x4′ x5′ x6′ x7′
Difference Bounds Relations
x1 x2 x3 x4 x5 x6 x7 x1′ x2′ x3′ x4′ x5′ x6′ x7′
Difference Bounds Relations
x1 x2 x3 x4 x5 x6 x7 x1′ x2′ x3′ x4′ x5′ x6′ x7′ γ0 γ1 γ1 γ2 γ3 γ4 γ5 γ6 γ7 γ8 γ9 γ2 γ3 γ4
Difference Bounds Relations
γ0 γ1 γ1 γ2 γ3 γ4 γ5 γ6 γ7 γ8 γ9 γ2 γ3 γ4
Difference Bounds Relations
γ0 γ1 γ1 γ2 γ3 γ4 γ5 γ6 γ7 γ8 γ9 γ2 γ3 γ4 → ‹ ‹ → → → → → ‹ → → → → → ‹ ‹ → → → → → ‹ ‹ → → → → ‹ → → → → ‹ → ‹ → ‹ ‹ → ‹ → → → ‹ → → → → ‹ → → → → → ‹ ‹ → → → → ‹ → → → → ‹ → ‹ q0 q1 q2 q2 q3 q4 q5 q7 q8 q9 q10 q2 q3 q4 q5
Zigzag Automata
q0 q1 q2 q3 q4 q5 q7 q8 q10 γ0 (0) γ1 (1) γ1 (1) γ2 (0) γ3 (1) γ4 (1) γ5 (1) γ6 (0) γ7 (-1) γ8 (-1) γ9 (0) → q6 γ5 (1) γ5 (1) γ5 (1) q9 γ8 (-1)
Zigzag Automata
- All paths in the n-th unfolding of the constraint graph are
encoded as runs of weighted automata [BIL’06]
- Minimal weight paths become minimal weight runs
q0 q1 q2 q3 q4 q5 q7 q8 q10 γ0 (0) γ1 (1) γ1 (1) γ2 (0) γ3 (1) γ4 (1) γ5 (1) γ6 (0) γ7 (-1) γ8 (-1) γ9 (0) → q6 γ5 (1) γ5 (1) γ5 (1) q9 γ8 (-1)
Zigzag Automata
q0 q1 q2 q3 q4 q5 q7 q8 q10 γ0 (0) γ1 (1) γ1 (1) γ2 (0) γ3 (1) γ4 (1) γ5 (1) γ6 (0) γ7 (-1) γ8 (-1) γ9 (0) → q6 γ5 (1) γ5 (1) γ5 (1) q9 γ8 (-1)
Zigzag Automata
- We compute a function on the automaton:
min_weightA(n) ¡= ¡min{ω(ρ) ¡| ¡ρ ¡is ¡a ¡run ¡of ¡A, ¡|ρ|=n}
- Minimal weight functions are periodic [deSchutter’00]
➡ mininal weight runs iterate through critical cycles
q0 q1 q2 q3 q4 q5 q7 q8 q10 γ0 (0) γ1 (1) γ1 (1) γ2 (0) γ3 (1) γ4 (1) γ5 (1) γ6 (0) γ7 (-1) γ8 (-1) γ9 (0) → q6 γ5 (1) γ5 (1) γ5 (1) q9 γ8 (-1)
Zigzag Automata
q0 q1 q3 q4 q5 q7 q8 q10 γ0 (0) γ1 (1) γ1 (1) γ2 (0) γ3 (1) γ4 (1) γ5 (1) γ6 (0) γ7 (-1) γ8 (-1) γ9 (0) → q6 γ5 (1) γ5 (1) γ5 (1) q9 γ8 (-1) q2
ϖ(γ1*) = ω(γ1) / | γ1 | = 1
Zigzag Automata
q0 q1 q3 q4 q5 q7 q8 q10 γ0 (0) γ1 (1) γ1 (1) γ2 (0) γ3 (1) γ4 (1) γ5 (1) γ6 (0) γ7 (-1) γ8 (-1) γ9 (0) → q6 γ5 (1) γ5 (1) γ5 (1) q9 γ8 (-1) q2
ϖ((γ2 γ3 γ4 γ5 γ6 γ7 γ8 γ9)*) = 1/8 ϖ(γ1*) = ω(γ1) / | γ1 | = 1
Zigzag Automata
q0 q1 q3 q4 q5 q7 q8 q10 γ0 (0) γ1 (1) γ1 (1) γ2 (0) γ3 (1) γ4 (1) γ5 (1) γ6 (0) γ7 (-1) γ8 (-1) γ9 (0) → q6 γ5 (1) γ5 (1) γ5 (1) γ8 (-1) q2 q9
ϖ(γ8*) = -1 ϖ((γ2 γ3 γ4 γ5 γ6 γ7 γ8 γ9)*) = 1/8 ϖ(γ1*) = ω(γ1) / | γ1 | = 1
Zigzag Automata
q0 q1 q3 q4 q5 q7 q8 q10 γ0 (0) γ1 (1) γ1 (1) γ2 (0) γ3 (1) γ4 (1) γ5 (1) γ6 (0) γ7 (-1) γ8 (-1) γ9 (0) → q6 γ5 (1) γ5 (1) γ5 (1) γ8 (-1) q2 q9
ϖ(γ8*) = -1
γ8* is a critical cycle in its SCC
ϖ((γ2 γ3 γ4 γ5 γ6 γ7 γ8 γ9)*) = 1/8 ϖ(γ1*) = ω(γ1) / | γ1 | = 1
Zigzag Automata
q0 q1 q3 q4 q5 q7 q8 q10 γ0 (0) γ1 (1) γ1 (1) γ2 (0) γ3 (1) γ4 (1) γ5 (1) γ6 (0) γ7 (-1) γ8 (-1) γ9 (0) → q6 γ5 (1) γ5 (1) γ5 (1) γ8 (-1) q2 q9
- 6
- 2
3 8 12 3 6 9 12 15 18 21 24 27 30
min weight length
Periodic Relations
x2 x2′ x1 x1′
1
- 1
- 2
2 ∞ 1
- 1
∞
- 2
2 ∞ ∞ ∞ ∞ ∞ ∞
Periodic Relations
x2 x2′ x1 x1′
1
- 1
- 2
2 ∞ 1
- 1
∞
- 2
2 ∞ ∞ ∞ ∞ ∞ ∞
x2′′ x1′′
1
- 1
- 2
2 ∞ -3 ∞
- 1 -3
∞ ∞ ∞ ∞ ∞ ∞
Periodic Relations
x2 x2′ x1 x1′
1
- 1
- 2
2 ∞ 1
- 1
∞
- 2
2 ∞ ∞ ∞ ∞ ∞ ∞
x2′′ x1′′
1
- 1
- 2
2 ∞ -3 ∞
- 1 -3
∞ ∞ ∞ ∞ ∞ ∞
x2′′′ x1′′′
1
- 1
- 2
2 ∞ -2 -4 ∞
- 5 -1
∞ ∞ ∞ ∞ ∞ ∞
Periodic Relations
x2 x2′ x1 x1′
1
- 1
- 2
2 ∞ 1
- 1
∞
- 2
2 ∞ ∞ ∞ ∞ ∞ ∞
x2′′ x1′′
1
- 1
- 2
2 ∞ -3 ∞
- 1 -3
∞ ∞ ∞ ∞ ∞ ∞
x2′′′ x1′′′
1
- 1
- 2
2 ∞ -2 -4 ∞
- 5 -1
∞ ∞ ∞ ∞ ∞ ∞
x2iv x1iv
1
- 1
- 2
2 ∞ -6 -2 ∞
- 4 -6
∞ ∞ ∞ ∞ ∞ ∞
Periodic Relations
x2 x2′ x1 x1′
1
- 1
- 2
2 ∞ 1
- 1
∞
- 2
2 ∞ ∞ ∞ ∞ ∞ ∞
x2′′ x1′′
1
- 1
- 2
2 ∞ -3 ∞
- 1 -3
∞ ∞ ∞ ∞ ∞ ∞
x2′′′ x1′′′
1
- 1
- 2
2 ∞ -2 -4 ∞
- 5 -1
∞ ∞ ∞ ∞ ∞ ∞
x2iv x1iv
1
- 1
- 2
2 ∞ -6 -2 ∞
- 4 -6
∞ ∞ ∞ ∞ ∞ ∞
x2v x1v
1
- 1
- 2
2 ∞ -5 -7 ∞
- 8 -4
∞ ∞ ∞ ∞ ∞ ∞
Periodic Relations
x2 x2′ x1 x1′
1
- 1
- 2
2 ∞ 1
- 1
∞
- 2
2 ∞ ∞ ∞ ∞ ∞ ∞
x2′′ x1′′
1
- 1
- 2
2 ∞ -3 ∞
- 1 -3
∞ ∞ ∞ ∞ ∞ ∞
x2′′′ x1′′′
1
- 1
- 2
2 ∞ -2 -4 ∞
- 5 -1
∞ ∞ ∞ ∞ ∞ ∞
x2iv x1iv
1
- 1
- 2
2 ∞ -6 -2 ∞
- 4 -6
∞ ∞ ∞ ∞ ∞ ∞
x2v x1v
1
- 1
- 2
2 ∞ -5 -7 ∞
- 8 -4
∞ ∞ ∞ ∞ ∞ ∞
x2vi x1vi
1
- 1
- 2
2 ∞ -9 -4 ∞
- 7 -9
∞ ∞ ∞ ∞ ∞ ∞
Periodic Relations
x2 x2′ x1 x1′
1
- 1
- 2
2 ∞ 1
- 1
∞
- 2
2 ∞ ∞ ∞ ∞ ∞ ∞
x2′′ x1′′
1
- 1
- 2
2 ∞ -3 ∞
- 1 -3
∞ ∞ ∞ ∞ ∞ ∞
x2′′′ x1′′′
1
- 1
- 2
2 ∞ -2 -4 ∞
- 5 -1
∞ ∞ ∞ ∞ ∞ ∞
x2iv x1iv
1
- 1
- 2
2 ∞ -6 -2 ∞
- 4 -6
∞ ∞ ∞ ∞ ∞ ∞
x2v x1v
1
- 1
- 2
2 ∞ -5 -7 ∞
- 8 -4
∞ ∞ ∞ ∞ ∞ ∞
x2vi x1vi
1
- 1
- 2
2 ∞ -9 -4 ∞
- 7 -9
∞ ∞ ∞ ∞ ∞ ∞ ∞ -3 -2 ∞
- 3 -3
∞ ∞ ∞ ∞ ∞ ∞ ∞ -3 -2 ∞
- 3 -3
∞ ∞ ∞ ∞ ∞ ∞
Periodic Relations
x2 x2′ x1 x1′
1
- 1
- 2
2 ∞ 1
- 1
∞
- 2
2 ∞ ∞ ∞ ∞ ∞ ∞
x2′′ x1′′
1
- 1
- 2
2 ∞ -3 ∞
- 1 -3
∞ ∞ ∞ ∞ ∞ ∞
x2′′′ x1′′′
1
- 1
- 2
2 ∞ -2 -4 ∞
- 5 -1
∞ ∞ ∞ ∞ ∞ ∞
x2iv x1iv
1
- 1
- 2
2 ∞ -6 -2 ∞
- 4 -6
∞ ∞ ∞ ∞ ∞ ∞
x2v x1v
1
- 1
- 2
2 ∞ -5 -7 ∞
- 8 -4
∞ ∞ ∞ ∞ ∞ ∞
x2vi x1vi
1
- 1
- 2
2 ∞ -9 -4 ∞
- 7 -9
∞ ∞ ∞ ∞ ∞ ∞ ∞ -3 -2 ∞
- 3 -3
∞ ∞ ∞ ∞ ∞ ∞ ∞ -3 -2 ∞
- 3 -3
∞ ∞ ∞ ∞ ∞ ∞ ∞ -3 -3 ∞
- 3 -3
∞ ∞ ∞ ∞ ∞ ∞ ∞ -3 -3 ∞
- 3 -3
∞ ∞ ∞ ∞ ∞ ∞
Periodicity and NTIME Safety
R(x,x′) q0 q2 q1 I(x′) F(x) →
Periodicity and NTIME Safety
R(x,x′) q0 q2 q1 I(x′) F(x) →
Quantifier-free Presburger arithmetic
Periodicity and NTIME Safety
The program is safe iff q2 is unreachable
R(x,x′) q0 q2 q1 I(x′) F(x) →
Quantifier-free Presburger arithmetic
Periodicity and NTIME Safety
The program is safe iff q2 is unreachable guess if ∃k>0 . Rk=∅ holds
R(x,x′) q0 q2 q1 I(x′) F(x) →
Quantifier-free Presburger arithmetic
Periodicity and NTIME Safety
yes guess b>0 check Rb-1 ≠ ∅ and Rb = ∅ compute Ri for some 0≤i<b I(x) ∧ Ri(x,x′) ∧ F(x′) sat? yes unsafe The program is safe iff q2 is unreachable guess if ∃k>0 . Rk=∅ holds
R(x,x′) q0 q2 q1 I(x′) F(x) →
Quantifier-free Presburger arithmetic
Periodicity and NTIME Safety
→ R(x,x′) q0 q2 q1 I(x′) F(x)
guess if ∃k>0 . Rk=∅ holds The program is safe iff q2 is unreachable
Periodicity and NTIME Safety
→ R(x,x′) q0 q2 q1 I(x′) F(x)
guess if ∃k>0 . Rk=∅ holds no guess b>0, c>0 compute Rb+j, Rb+c+j for some 0≤j<c compute Λj such that Rb+c+j = Rb+j ⊕ Λj check ∀k≥0 . k⋅Λj ⊕ Rb+j ≠ ∅ and ∀k≥0 . (k⋅Λj ⊕ Rb+j)•Rc= (k+1)⋅Λj ⊕ Rb+j I ∧ [Ri ∨ (k≥0 ∧ k⋅Λj ⊕ Rb+j)] ∧ F sat? compute Ri for some 0≤i<b yes unsafe The program is safe iff q2 is unreachable
Computing EXP Powers in PTIME
- Def. ¡A ¡class ¡of ¡relations ¡is ¡poly-‑logarithmic ¡iff:
- 1. ¡||Rn||2=O((||R||2⋅log2 ¡n)k), ¡for ¡some ¡k>0
- 2. ¡P•Q ¡can ¡be ¡computed ¡in ¡PTIME(||P||2+||Q||2)
Computing EXP Powers in PTIME
- Def. ¡A ¡class ¡of ¡relations ¡is ¡poly-‑logarithmic ¡iff:
- 1. ¡||Rn||2=O((||R||2⋅log2 ¡n)k), ¡for ¡some ¡k>0
- 2. ¡P•Q ¡can ¡be ¡computed ¡in ¡PTIME(||P||2+||Q||2)
FastPower(R,n) Q←R P←Id for i=1,...,⎡log2 n⎤ if the i-th bit of n is 1 then P←P•Q Q←Q•Q return P
Computing EXP Powers in PTIME
- Def. ¡A ¡class ¡of ¡relations ¡is ¡poly-‑logarithmic ¡iff:
- 1. ¡||Rn||2=O((||R||2⋅log2 ¡n)k), ¡for ¡some ¡k>0
- 2. ¡P•Q ¡can ¡be ¡computed ¡in ¡PTIME(||P||2+||Q||2)
FastPower(R,n) Q←R P←Id for i=1,...,⎡log2 n⎤ if the i-th bit of n is 1 then P←P•Q Q←Q•Q return P
If R is poly-logarithmic, Rk can be computed in PTIME(n), for k=O(2n)
Deciding safety in NPTIME
- Def. ¡A ¡periodic ¡class ¡of ¡relations ¡is ¡exponential ¡iff:
- 1. ¡the ¡prePix ¡b ¡and ¡period ¡c ¡of ¡any ¡relation ¡R ¡are ¡both ¡EXP(||R||2)
- 2. ¡for ¡all ¡0≤i<c, ¡if ¡Rb+c+i ¡= ¡Rb+c ¡⊕ Λi, ¡the ¡following ¡conditions:
- ¡∀k≥0 ¡. ¡k⋅Λi ¡⊕ Rb+i ¡ ¡≠ ¡∅
- ¡∀k≥0 ¡. ¡(k⋅Λj ¡⊕ Rb+j)•Rc= ¡(k+1)⋅Λj ¡ ¡⊕ Rb+j
can ¡be ¡checked ¡in ¡NPTIME(||R||2).
Deciding safety in NPTIME
- Def. ¡A ¡periodic ¡class ¡of ¡relations ¡is ¡exponential ¡iff:
- 1. ¡the ¡prePix ¡b ¡and ¡period ¡c ¡of ¡any ¡relation ¡R ¡are ¡both ¡EXP(||R||2)
- 2. ¡for ¡all ¡0≤i<c, ¡if ¡Rb+c+i ¡= ¡Rb+c ¡⊕ Λi, ¡the ¡following ¡conditions:
- ¡∀k≥0 ¡. ¡k⋅Λi ¡⊕ Rb+i ¡ ¡≠ ¡∅
- ¡∀k≥0 ¡. ¡(k⋅Λj ¡⊕ Rb+j)•Rc= ¡(k+1)⋅Λj ¡ ¡⊕ Rb+j
can ¡be ¡checked ¡in ¡NPTIME(||R||2).
(*-consistency) (periodicity)
Deciding safety in NPTIME
- Def. ¡A ¡periodic ¡class ¡of ¡relations ¡is ¡exponential ¡iff:
- 1. ¡the ¡prePix ¡b ¡and ¡period ¡c ¡of ¡any ¡relation ¡R ¡are ¡both ¡EXP(||R||2)
- 2. ¡for ¡all ¡0≤i<c, ¡if ¡Rb+c+i ¡= ¡Rb+c ¡⊕ Λi, ¡the ¡following ¡conditions:
- ¡∀k≥0 ¡. ¡k⋅Λi ¡⊕ Rb+i ¡ ¡≠ ¡∅
- ¡∀k≥0 ¡. ¡(k⋅Λj ¡⊕ Rb+j)•Rc= ¡(k+1)⋅Λj ¡ ¡⊕ Rb+j
can ¡be ¡checked ¡in ¡NPTIME(||R||2). If R is exponential, all branches of the non-deterministic decision procedure for safety take PTIME(||R||2). Then:
- ||I(x) ∧ Ri(x,x′) ∧ F(x′)||2 = O((||I||2 +||R||2+||F||2)k)
- ||I(x) ∧ [Ri ∨ (k≥0 ∧ k⋅Λj ⊕ Rb+j)] ∧ F(x′)||2 = O((||I||2 +||R||2+||F||2)k)
for some k>0.
(*-consistency) (periodicity)
Deciding safety in NPTIME
- Def. ¡A ¡periodic ¡class ¡of ¡relations ¡is ¡exponential ¡iff:
- 1. ¡the ¡prePix ¡b ¡and ¡period ¡c ¡of ¡any ¡relation ¡R ¡are ¡both ¡EXP(||R||2)
- 2. ¡for ¡all ¡0≤i<c, ¡if ¡Rb+c+i ¡= ¡Rb+c ¡⊕ Λi, ¡the ¡following ¡conditions:
- ¡∀k≥0 ¡. ¡k⋅Λi ¡⊕ Rb+i ¡ ¡≠ ¡∅
- ¡∀k≥0 ¡. ¡(k⋅Λj ¡⊕ Rb+j)•Rc= ¡(k+1)⋅Λj ¡ ¡⊕ Rb+j
can ¡be ¡checked ¡in ¡NPTIME(||R||2). If R is exponential, all branches of the non-deterministic decision procedure for safety take PTIME(||R||2). Then:
- ||I(x) ∧ Ri(x,x′) ∧ F(x′)||2 = O((||I||2 +||R||2+||F||2)k)
- ||I(x) ∧ [Ri ∨ (k≥0 ∧ k⋅Λj ⊕ Rb+j)] ∧ F(x′)||2 = O((||I||2 +||R||2+||F||2)k)
for some k>0.
(*-consistency) (periodicity)
Since these are quantifier-free Presburger formulae, then SAT (and also safety) is in NPTIME(||I||2 +||R||2+||F||2)!
NP *-Consistency and Periodicity
x2 x2′ x1 x1′
1
- 1
- 2
2
prefix b = 2 period c = 2
∞ -3 -2 ∞
- 3 -3
∞ ∞ ∞ ∞ ∞ ∞
rate Λ =
NP *-Consistency and Periodicity
x2 x2′ x1 x1′
- 3-3k
- 2k
- 1-3k
prefix b = 2 period c = 2
∞ -3 -2 ∞
- 3 -3
∞ ∞ ∞ ∞ ∞ ∞
rate Λ =
- 3-3k
{R2+2k}k≥0
NP *-Consistency and Periodicity
x2 x2′ x1 x1′
- 3-3k
- 2k
- 1-3k
prefix b = 2 period c = 2
∞ -3 -2 ∞
- 3 -3
∞ ∞ ∞ ∞ ∞ ∞
rate Λ =
- 3-3k
{R2+2k}k≥0
¡∀k≥0 ¡. ¡k⋅Λ ¡⊕ Rb ¡≠ ¡∅ ¡ ¡ ¡?
NP *-Consistency and Periodicity
prefix b = 2 period c = 2
∞ -3 -2 ∞
- 3 -3
∞ ∞ ∞ ∞ ∞ ∞
rate Λ = x2 x2′ x1 x1′
- 3-3k
- 2k
- 1-3k
- 3-3k
x2′′ x1′′
1
- 1
- 2
2
? ≡
x2 x2′′ x1 x1′′
- 3-3(k+1)
- 2(k+1)
- 1-3(k+1)
- 3-3(k+1)
¡∀k≥0 ¡. ¡(k⋅Λ ¡⊕ Rb)•Rc= ¡(k+1)⋅Λ ¡ ¡⊕ Rb ¡ ¡ ¡?
NP *-Consistency and Periodicity
prefix b = 2 period c = 2
∞ -3 -2 ∞
- 3 -3
∞ ∞ ∞ ∞ ∞ ∞
rate Λ = x2 x1 x2′′ x1′′
? ≡
x2 x2′′ x1 x1′′
- 3-3(k+1)
- 2(k+1)
- 1-3(k+1)
- 3-3(k+1)
¡∀k≥0 ¡. ¡(k⋅Λ ¡⊕ Rb)•Rc= ¡(k+1)⋅Λ ¡ ¡⊕ Rb ¡ ¡ ¡?
min(-2-3k,-2-2k) min(-2-3k,-1-3k) min(-4-3k,-2-2k) min(-3k,-5-3k)
Bounding the Prefix
- Thm. ¡Given ¡a ¡weighted ¡graph ¡G ¡with ¡n ¡nodes, ¡the ¡weights ¡of ¡the ¡
minimal ¡paths ¡between ¡two ¡vertices ¡form ¡a ¡periodic ¡sequence ¡ with ¡prePix ¡at ¡most ¡max(n4, ¡n6⋅M), ¡where ¡M ¡is ¡the ¡maximum ¡ absolute ¡value ¡among ¡the ¡labels ¡of ¡G. ¡ ¡
→ 1000
- 1
Bounding the Prefix
- Thm. ¡Given ¡a ¡weighted ¡graph ¡G ¡with ¡n ¡nodes, ¡the ¡weights ¡of ¡the ¡
minimal ¡paths ¡between ¡two ¡vertices ¡form ¡a ¡periodic ¡sequence ¡ with ¡prePix ¡at ¡most ¡max(n4, ¡n6⋅M), ¡where ¡M ¡is ¡the ¡maximum ¡ absolute ¡value ¡among ¡the ¡labels ¡of ¡G. ¡ ¡
→ 1000
- 1
Bounding the Prefix
- Thm. ¡Given ¡a ¡weighted ¡graph ¡G ¡with ¡n ¡nodes, ¡the ¡weights ¡of ¡the ¡
minimal ¡paths ¡between ¡two ¡vertices ¡form ¡a ¡periodic ¡sequence ¡ with ¡prePix ¡at ¡most ¡max(n4, ¡n6⋅M), ¡where ¡M ¡is ¡the ¡maximum ¡ absolute ¡value ¡among ¡the ¡labels ¡of ¡G. ¡ ¡
→ 1000
- 1
A zigzag automaton has at most 5N=2O(N) states, where N is the number of dimensions of the DB relation R ⊆ ZN × ZN
➡ states are N-tuples from the set {→, ←, ‹, ›, ⊥}, of cardinality 5 ➡ the absolute values of the labels are of the order of 2O(||R||2)
Bounding the Period
Thm.[deSchutter00] ¡Given ¡a ¡weighted ¡graph ¡G, ¡and ¡a ¡partition ¡of ¡G ¡ in ¡SCCs ¡W1, ¡..., ¡Wk, ¡the ¡weights ¡of ¡the ¡minimal ¡paths ¡between ¡ two ¡vertices ¡form ¡a ¡periodic ¡sequence ¡of ¡period ¡lcm(c1, ¡..., ¡ck):
- ¡ci ¡= ¡gcd ¡{ ¡|ρ| ¡| ¡ρ ¡is ¡a ¡critical ¡cycle ¡in ¡Wi}, ¡for ¡all ¡i=1,...,k. ¡
Bounding the Period
Thm.[deSchutter00] ¡Given ¡a ¡weighted ¡graph ¡G, ¡and ¡a ¡partition ¡of ¡G ¡ in ¡SCCs ¡W1, ¡..., ¡Wk, ¡the ¡weights ¡of ¡the ¡minimal ¡paths ¡between ¡ two ¡vertices ¡form ¡a ¡periodic ¡sequence ¡of ¡period ¡lcm(c1, ¡..., ¡ck):
- ¡ci ¡= ¡gcd ¡{ ¡|ρ| ¡| ¡ρ ¡is ¡a ¡critical ¡cycle ¡in ¡Wi}, ¡for ¡all ¡i=1,...,k. ¡
Every SCC of a zigzag automaton A has a critical cycle ρ ¡of length: |ρ| ¡| lcm(1,...,N) where R ⊆ ZN × ZN is the DB relation for A
➡ ci divides lcm(1,...,N), for all i = 1,...,k ➡ the period is at most lcm(1,...,N) = 2O(N) = 2O(||R||2)
Bounding the Period
x1 x2 x3 x4 x5 x6 x7 x1′ x2′ x3′ x4′ x5′ x6′ x7′ γ0 γ1 γ1 γ2 γ3 γ4 γ5 γ6 γ7 γ8 γ9 γ2 γ3 γ4 q0 q q q q q q q1 γ0 γ1 γ1 γ2 γ3 γ4 γ5 γ6 γ7 γ8 γ9 → q γ5 γ5 γ5 γ8 q q
NP-complete Safety for DB Loops
- Difference bounds relations are exponential
➡ the prefix and period of R are of the order of 2O(||R||2)
- Safety of flat integer programs with DB loops is in NP
- NP-hardness is by reduction from satisfiability of
Quantifier-free Presburger Arithmetic
NP-complete Safety for DB Loops
- Difference bounds relations are exponential
➡ the prefix and period of R are of the order of 2O(||R||2)
- Safety of flat integer programs with DB loops is in NP
- NP-hardness is by reduction from satisfiability of
Quantifier-free Presburger Arithmetic
x′=x q0 q2 q1 I(x′) →
Quantifier-free Presburger arithmetic
x′=x
Octagonal Relations
- Octagonal relations are encoded as DB relations on
twice the number of dimensions
x + y′ ≤ 1 x+ - y-′ ≤ 1 y+′ - x- ≤ 1
≡
Octagonal Relations
- Octagonal relations are encoded as DB relations on
twice the number of dimensions
x + y′ ≤ 1 x+ - y-′ ≤ 1 y+′ - x- ≤ 1
≡
x+ + x- = 0 y+′ + y-′= 0
Octagonal Relations
- Octagonal relations are encoded as DB relations on
twice the number of dimensions
x + y′ ≤ 1 x+ - y-′ ≤ 1 y+′ - x- ≤ 1
≡
x+ + x- = 0 y+′ + y-′= 0
- Closed under relational composition:
➡
composition of octagonal relations requires an additional tightening step
- Oct. relations are periodic, poly-logarithmic and exponential
➡
the prefix and period of R are also of the order of 2O(||R||2)
- Safety problems are NP-complete for integer flat programs
with octagonal loops
Conclusions
- Safety can be decided for integer programs whenever:
➡
there are no nested loops in the control structure
➡
all loops are labeled with relations definable by octagonal constraints
- The safety problems are NP-complete in these cases
- We have implemented an efficient algorithm [BIK’10]:
➡
function summarization in inter-procedural analysis
➡
abstraction refinement for interpolation-based model checking
➡
termination analysis
➡
analysis of programs with integer arrays
Conclusions
- Safety can be decided for integer programs whenever:
➡
there are no nested loops in the control structure
➡
all loops are labeled with relations definable by octagonal constraints
- The safety problems are NP-complete in these cases
- We have implemented an efficient algorithm [BIK’10]:
➡
function summarization in inter-procedural analysis
➡
abstraction refinement for interpolation-based model checking
➡
termination analysis
➡
analysis of programs with integer arrays