Safety Problems are NP-complete for Flat Integer Programs with - - PowerPoint PPT Presentation

safety problems are np complete for flat integer programs
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Safety Problems are NP-complete for Flat Integer Programs with Octagonal Loops

Marius Bozga, Radu Iosif (Verimag/CNRS, France) Filip Konecny (EPFL, Switzerland)

slide-2
SLIDE 2

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

slide-3
SLIDE 3

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);

slide-4
SLIDE 4

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

slide-5
SLIDE 5

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);

slide-6
SLIDE 6

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

slide-7
SLIDE 7

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

slide-8
SLIDE 8

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

slide-9
SLIDE 9

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

slide-10
SLIDE 10

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

slide-11
SLIDE 11

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

slide-12
SLIDE 12

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

slide-13
SLIDE 13

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

slide-14
SLIDE 14

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

slide-15
SLIDE 15

Difference Bounds Relations

x2 x2′ x1 x1′

slide-16
SLIDE 16

Difference Bounds Relations

x2 x2′ x1 x1′

1

x1 - x1′ ≤ 1

slide-17
SLIDE 17

Difference Bounds Relations

x2 x2′ x1 x1′

1

x1 - x1′ ≤ 1

  • 1

x1 - x2′ ≤ -1

slide-18
SLIDE 18

Difference Bounds Relations

x2 x2′ x1 x1′

1

x1 - x1′ ≤ 1

  • 1

x1 - x2′ ≤ -1

  • 2

x2 - x1′ ≤ -2

slide-19
SLIDE 19

Difference Bounds Relations

x2 x2′ x1 x1′

1

x1 - x1′ ≤ 1

  • 1

x1 - x2′ ≤ -1

  • 2

x2 - x1′ ≤ -2

2

x2 - x2′ ≤ 2

slide-20
SLIDE 20

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′

∞ ∞ ∞

slide-21
SLIDE 21

Difference Bounds Relations

x2 x1 x2′ x1′

1

  • 1
  • 2

2

slide-22
SLIDE 22

Difference Bounds Relations

x2 x1 x2′ x1′

1

  • 1
  • 2

2

x2′′ x1′′

1

  • 1
  • 2

2

slide-23
SLIDE 23

Difference Bounds Relations

x2 x1 x2′ x1′

1

  • 1
  • 2

2

x2′′ x1′′

1

  • 1
  • 2

2

x2′′′ x1′′′

1

  • 1
  • 2

2

slide-24
SLIDE 24

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

slide-25
SLIDE 25

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

slide-26
SLIDE 26

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

slide-27
SLIDE 27

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

slide-28
SLIDE 28

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

slide-29
SLIDE 29

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

slide-30
SLIDE 30

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
slide-31
SLIDE 31

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

slide-32
SLIDE 32

Difference Bounds Relations

x1 x2 x3 x4 x5 x6 x7 x1′ x2′ x3′ x4′ x5′ x6′ x7′

slide-33
SLIDE 33

Difference Bounds Relations

x1 x2 x3 x4 x5 x6 x7 x1′ x2′ x3′ x4′ x5′ x6′ x7′

slide-34
SLIDE 34

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

slide-35
SLIDE 35

Difference Bounds Relations

γ0 γ1 γ1 γ2 γ3 γ4 γ5 γ6 γ7 γ8 γ9 γ2 γ3 γ4

slide-36
SLIDE 36

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

slide-37
SLIDE 37

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)

slide-38
SLIDE 38

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)

slide-39
SLIDE 39

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)

slide-40
SLIDE 40

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)

slide-41
SLIDE 41

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

slide-42
SLIDE 42

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

slide-43
SLIDE 43

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

slide-44
SLIDE 44

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

slide-45
SLIDE 45

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

slide-46
SLIDE 46

Periodic Relations

x2 x2′ x1 x1′

1

  • 1
  • 2

2 ∞ 1

  • 1

  • 2

2 ∞ ∞ ∞ ∞ ∞ ∞

slide-47
SLIDE 47

Periodic Relations

x2 x2′ x1 x1′

1

  • 1
  • 2

2 ∞ 1

  • 1

  • 2

2 ∞ ∞ ∞ ∞ ∞ ∞

x2′′ x1′′

1

  • 1
  • 2

2 ∞ -3 ∞

  • 1 -3

∞ ∞ ∞ ∞ ∞ ∞

slide-48
SLIDE 48

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

∞ ∞ ∞ ∞ ∞ ∞

slide-49
SLIDE 49

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

∞ ∞ ∞ ∞ ∞ ∞

slide-50
SLIDE 50

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

∞ ∞ ∞ ∞ ∞ ∞

slide-51
SLIDE 51

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

∞ ∞ ∞ ∞ ∞ ∞

slide-52
SLIDE 52

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

∞ ∞ ∞ ∞ ∞ ∞

slide-53
SLIDE 53

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

∞ ∞ ∞ ∞ ∞ ∞

slide-54
SLIDE 54

Periodicity and NTIME Safety

R(x,x′) q0 q2 q1 I(x′) F(x) →

slide-55
SLIDE 55

Periodicity and NTIME Safety

R(x,x′) q0 q2 q1 I(x′) F(x) →

Quantifier-free Presburger arithmetic

slide-56
SLIDE 56

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

slide-57
SLIDE 57

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

slide-58
SLIDE 58

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

slide-59
SLIDE 59

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

slide-60
SLIDE 60

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

slide-61
SLIDE 61

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)
slide-62
SLIDE 62

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

slide-63
SLIDE 63

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)

slide-64
SLIDE 64

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).

slide-65
SLIDE 65

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)

slide-66
SLIDE 66

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)

slide-67
SLIDE 67

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)!

slide-68
SLIDE 68

NP *-Consistency and Periodicity

x2 x2′ x1 x1′

1

  • 1
  • 2

2

prefix b = 2 period c = 2

∞ -3 -2 ∞

  • 3 -3

∞ ∞ ∞ ∞ ∞ ∞

rate Λ =

slide-69
SLIDE 69

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

slide-70
SLIDE 70

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 ¡≠ ¡∅ ¡ ¡ ¡?

slide-71
SLIDE 71

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 ¡ ¡ ¡?

slide-72
SLIDE 72

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)

slide-73
SLIDE 73

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
slide-74
SLIDE 74

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
slide-75
SLIDE 75

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)

slide-76
SLIDE 76

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. ¡
slide-77
SLIDE 77

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)

slide-78
SLIDE 78

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

slide-79
SLIDE 79

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

slide-80
SLIDE 80

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

slide-81
SLIDE 81

Octagonal Relations

  • Octagonal relations are encoded as DB relations on

twice the number of dimensions

x + y′ ≤ 1 x+ - y-′ ≤ 1 y+′ - x- ≤ 1

slide-82
SLIDE 82

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

slide-83
SLIDE 83

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

slide-84
SLIDE 84

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

slide-85
SLIDE 85

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

http://nts.imag.fr/index.php/Flata