Part II: Symbolic reachability for prefix rewriting Case study: - - PowerPoint PPT Presentation

part ii symbolic reachability for prefix rewriting case
SMART_READER_LITE
LIVE PREVIEW

Part II: Symbolic reachability for prefix rewriting Case study: - - PowerPoint PPT Presentation

Part II: Symbolic reachability for prefix rewriting Case study: Drawing skylines static Random r = new Random(); static void m() { if (r.nextBoolean()) { s(); right(); if (r.nextBoolean()) m(); } else { up(); m(); down(); } } static void s() {


slide-1
SLIDE 1

Part II: Symbolic reachability for prefix rewriting

slide-2
SLIDE 2

Case study: Drawing skylines

static Random r = new Random(); static void m() { if (r.nextBoolean()) { s(); right(); if (r.nextBoolean()) m();

}

else { up(); m(); down(); }

}

static void s() { if (r.nextBoolean()) return; up(); m(); down();

}

public static void main() { s(); }

1

slide-3
SLIDE 3

Model

static void s() { var st:stack of {s0, . . . , s5, . . .} s0: if (r.nextBoolean()) s0 → s1 s0 → s2 s1: return; s1 → ǫ s2: up(); s2 → up0 s3 s3: m(); s3 → m0 s4 s4: down(); s4 → down0 s5 s5: s5 → ǫ

}

2

slide-4
SLIDE 4

Symbolic reachability in prefix rewriting

Recall: program state ( g, ℓ, n, (ℓ1, n1) . . . (ℓk, nk) ) modelled as a word g ℓ, n ℓ1, n1 . . . ℓk, nk. Denote by G the alphabet of valuations of globals. Denote by L the alphabet of pairs ℓ, n. The set of possible programs states is given by G L∗

3

slide-5
SLIDE 5

A subset of GL∗ words is regular if it can be recognized by a finite automaton. Typically, the sets I and D of initial and dangerous program states are regular

  • sets. (Even very simple ones, like g l L∗.)

Challenge: show that if S ⊆ GL∗ is (effectively) regular, then so are pre∗(S) and post∗(S). This gives a procedure to check if I ∩ pre∗(D) = ∅ or post∗(I) ∩ D = ∅.

4

slide-6
SLIDE 6

Symbolic search

Forward symbolic search Initialize S := I Iterate S := S ∪ post(S) until fixpoint. Backward search: replace I by D, replace post by pre. Questions:

  • Are S ∪ post(S) and S ∪ pre(S) regular for regular S ?
  • Does the search terminate ?

We answer these questions for backward search, the forward case is similar.

5

slide-7
SLIDE 7

If S regular, then S ∪ pre(S) regular

We represent a regular set S ⊆ G L∗ by an NFA.

  • G as set of initial states, L as alphabet.
  • gw recognized if g

w

− − → q for some final state q. Example: G = {g0, g1} and L = {l0, l1} Automaton coding the set g0 l∗

1 l0 + l1 l1 :

g0 g1 l0 l0 l1 l1

6

slide-8
SLIDE 8

R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 l0 l0 l1 l1

7

slide-9
SLIDE 9

R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′ g′

1

l0 l0 l1 l1

8

slide-10
SLIDE 10

R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′ g′

1

l0 l0 l1 l1

9

slide-11
SLIDE 11

R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′ g′

1

l0 l0 l1 l1 l0

10

slide-12
SLIDE 12

R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′ g′

1

l0 l0 l1 l1 l0

11

slide-13
SLIDE 13

R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′ g′

1

l0 l0 l1 l1 l0 l1

12

slide-14
SLIDE 14

R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′ g′

1

l0 l0 l1 l1 l0 l1

13

slide-15
SLIDE 15

R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′ g′

1

l0 l0 l1 l1 l0 l1

14

slide-16
SLIDE 16

R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′ g′

1

l0 l0 l1 l1 l0 l1

15

slide-17
SLIDE 17

R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′ g′

1

l0 l0 l1 l1 l0 l1 l0 l1

16

slide-18
SLIDE 18

R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′ l0 l0 l1 l0 l1 l0 l1

17

slide-19
SLIDE 19

R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′′ g′′

1

g′ l0 l0 l1 l0 l1 l0 l1

18

slide-20
SLIDE 20

R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′′ g′′

1

g′ l0 l0 l1 l0 l1 l0 l1

19

slide-21
SLIDE 21

R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′′ g′′

1

g′ l0 l0 l1 l0 l1 l0 l1 l0

20

slide-22
SLIDE 22

R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′′ g′′

1

g′ l0 l0 l1 l0 l1 l0 l1 l0

21

slide-23
SLIDE 23

R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′′ g′′

1

g′ l0 l0 l1 l0 l1 l0 l1 l0 l1

22

slide-24
SLIDE 24

R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′′ g′′

1

g′ l0 l0 l1 l0 l1 l0 l1 l0 l1

23

slide-25
SLIDE 25

R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′′ g′′

1

g′ l0 l0 l1 l0 l1 l0 l1 l0 l1 l1

24

slide-26
SLIDE 26

R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′′ g′′

1

g′ l0 l0 l1 l0 l1 l0 l1 l0 l1 l1

25

slide-27
SLIDE 27

R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 l0 l0 l1 l0 l0 l0 l0 l0 l1 l1 l1 l1

26

slide-28
SLIDE 28

R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 l0 l0 l1 l0 l0 l0 l0 l0 l1 l1 l1 l1

27

slide-29
SLIDE 29

Termination fails

G = {g0, g1}, L = {l0, l1} R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 } S0 = D = g0 l0 l∗

1 l0 + g1 l1

S1 = S0 ∪ pre(S0) = g0 (l0 + l2

0) l∗ 1 l0 +

g1 l1 (ǫ + l0) l∗

1 (ǫ + l0)

· · · Si = Si−1 ∪ pre(Si−1) = g0 (l0 + . . . + li+1 ) l∗

1 l0 +

g1 l1 (ǫ + l0 + . . . + li

0) l∗ 1(ǫ + l0)

· · ·

28

slide-30
SLIDE 30

Termination fails

G = {g0, g1}, L = {l0, l1} R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 } S0 = D = g0 l0 l∗

1 l0 + g1 l1

S1 = S0 ∪ pre(S0) = g0 (l0 + l2

0) l∗ 1 l0 +

g1 l1 (ǫ + l0) l∗

1 (ǫ + l0)

· · · Si = Si−1 ∪ pre(Si−1) = g0 (l0 + . . . + li+1 ) l∗

1 l0 +

g1 l1 (ǫ + l0 + . . . + li

0) l∗ 1(ǫ + l0)

· · ·

29

slide-31
SLIDE 31

Termination fails

G = {g0, g1}, L = {l0, l1} R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 } S0 = D = g0 l0 l∗

1 l0 + g1 l1

S1 = S0 ∪ pre(S0) = g0 (l0 + l2

0) l∗ 1 l0 +

g1 l1 (ǫ + l0) l∗

1 (ǫ + l0)

· · · Si = Si−1 ∪ pre(Si−1) = g0 (l0 + . . . + li+1 ) l∗

1 l0 +

g1 l1 (ǫ + l0 + . . . + li

0) l∗ 1(ǫ + l0)

· · ·

30

slide-32
SLIDE 32

Termination fails

G = {g0, g1}, L = {l0, l1} R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 } S0 = D = g0 l0 l∗

1 l0 + g1 l1

S1 = S0 ∪ pre(S0) = g0 (l0 + l2

0) l∗ 1 l0 +

g1 l1 (ǫ + l0) l∗

1 (ǫ + l0)

· · · Si = Si−1 ∪ pre(Si−1) = g0 (l0 + . . . + li+1 ) l∗

1 l0 +

g1 l1 (ǫ + l0 + . . . + li

0) l∗ 1(ǫ + l0)

· · ·

31

slide-33
SLIDE 33

However, the fixpoint pre∗(D) = g0 l+

0 l∗ 1 l0 +

g1 l1 l∗

0 l∗ 1 (ǫ + l0)

is regular.

How can we compute it?

32

slide-34
SLIDE 34

Accelerations

By definition, pre(D) =

i≥0 Si

where S0 = D and Si+1 = Si ∪ pre(Si) for every i ≥ 0 If convergence fails, try to compute an acceleration : a sequence T0 ⊆ T1 ⊆ T2 . . . such that (a) ∀i ≥ 0: Si ⊆ Ti (b) ∀i ≥ 0: Ti ⊆

j≥0 Sj = pre(D)

Property (a) ensures capture of (at least) the whole set pre(D) Property (b) ensures that only elements of pre(D) are captured The acceleration guarantees termination if (c) ∃i ≥ 0: Ti+1 = Ti

33

slide-35
SLIDE 35

An acceleration for prefix rewriting

Idea: reuse the same states R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

true/y := 0 y = 1 / id x < 1 / id x < 1 / id y < 1 / y := 0 x > 1 / id +? true/x, y := x+?, y+? true/x, y := x+?, y+? true/x, y := x+?, y+? true/y := 0 y = 1 / id x < 1 / id x < 1 / id y < 1 / y := 0 true/x, y := x+?, y+? true/x, y := x+?, y+? true/x, y := x+?, y+? true/x, y :=

34

slide-36
SLIDE 36

An acceleration for prefix rewriting

Idea: reuse the same states R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 l0 l0 l1 l1 g0 g1 l0 l0 l1 l1

35

slide-37
SLIDE 37

An acceleration for prefix rewriting

Idea: reuse the same states R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′ g′

1

l0 l0 l1 l1 g0 g1 l0 l0 l1 l1

36

slide-38
SLIDE 38

An acceleration for prefix rewriting

Idea: reuse the same states R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′ g′

1

l0 l0 l1 l1 g0 g1 l0 l0 l1 l1

37

slide-39
SLIDE 39

An acceleration for prefix rewriting

Idea: reuse the same states R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′ g′

1

l0 l0 l1 l1 l0 g0 g1 l0 l0 l1 l1

38

slide-40
SLIDE 40

An acceleration for prefix rewriting

Idea: reuse the same states R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′ g′

1

l0 l0 l1 l1 l0 g0 g1 l0 l0 l1 l1 l0

39

slide-41
SLIDE 41

An acceleration for prefix rewriting

Idea: reuse the same states R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′ g′

1

l0 l0 l1 l1 l0 g0 g1 l0 l0 l1 l1 l0

40

slide-42
SLIDE 42

An acceleration for prefix rewriting

Idea: reuse the same states R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′ g′

1

l0 l0 l1 l1 l0 l1 g0 g1 l0 l0 l1 l1 l0

41

slide-43
SLIDE 43

An acceleration for prefix rewriting

Idea: reuse the same states R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′ g′

1

l0 l0 l1 l1 l0 l1 g0 g1 l0 l0 l1 l1 l0 l1

42

slide-44
SLIDE 44

An acceleration for prefix rewriting

Idea: reuse the same states R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′ g′

1

l0 l0 l1 l1 l0 l1 g0 g1 l0 l0 l1 l1 l0 l1

43

slide-45
SLIDE 45

An acceleration for prefix rewriting

Idea: reuse the same states R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′ g′

1

l0 l0 l1 l1 l0 l1 g0 g1 l0 l0 l1 l1 l0 l1

44

slide-46
SLIDE 46

An acceleration for prefix rewriting

Idea: reuse the same states R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′ g′

1

l0 l0 l1 l1 l0 l1 l0 l1 g0 g1 l0 l0 l1 l1 l0 l1

45

slide-47
SLIDE 47

An acceleration for prefix rewriting

Idea: reuse the same states R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′′ g′′

1

g′ l0 l0 l1 l0 l1 l0 l1 g0 g1 l0 l0 l1 l1 l0 l1

46

slide-48
SLIDE 48

An acceleration for prefix rewriting

Idea: reuse the same states R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′′ g′′

1

g′ l0 l0 l1 l0 l1 l0 l1 g0 g1 l0 l0 l1 l1 l0 l1

47

slide-49
SLIDE 49

An acceleration for prefix rewriting

Idea: reuse the same states R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′′ g′′

1

g′ l0 l0 l1 l0 l1 l0 l1 l0 g0 g1 l0 l0 l1 l1 l0 l1

48

slide-50
SLIDE 50

An acceleration for prefix rewriting

Idea: reuse the same states R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′′ g′′

1

g′ l0 l0 l1 l0 l1 l0 l1 l0 g0 g1 l0 l0 l1 l1 l0 l1

49

slide-51
SLIDE 51

An acceleration for prefix rewriting

Idea: reuse the same states R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′′ g′′

1

g′ l0 l0 l1 l0 l1 l0 l1 l0 l1 g0 g1 l0 l0 l1 l1 l0 l1

50

slide-52
SLIDE 52

An acceleration for prefix rewriting

Idea: reuse the same states R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′′ g′′

1

g′ l0 l0 l1 l0 l1 l0 l1 l0 l1 g0 g1 l0 l0 l1 l1 l0 l1

51

slide-53
SLIDE 53

An acceleration for prefix rewriting

Idea: reuse the same states R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′′ g′′

1

g′ l0 l0 l1 l0 l1 l0 l1 l0 l1 l1 g0 g1 l0 l0 l1 l1 l0 l1

52

slide-54
SLIDE 54

An acceleration for prefix rewriting

Idea: reuse the same states R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′′ g′′

1

g′ l0 l0 l1 l0 l1 l0 l1 l0 l1 l1 g0 g1 l0 l0 l1 l1 l0 l1 l1

53

slide-55
SLIDE 55

An acceleration for prefix rewriting

Idea: reuse the same states R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 g′′ g′′

1

g′ l0 l0 l1 l0 l1 l0 l1 l0 l1 l1 g0 g1 l0 l0 l1 l1 l0 l1 l1

54

slide-56
SLIDE 56

An acceleration for prefix rewriting

Idea: reuse the same states R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

true/y := 0 y = 1 / id x < 1 / id x < 1 / id y < 1 / y := 0 x > 1 / id true/x, y := x+?, y+? true/x, y := x+?, y+? true/x, y := x+?, y+? true/x, y := x+?, y+?

g0 g1 l0 l0 l1 l1 l0 l1 l1

55

slide-57
SLIDE 57

But does it work . . . ?

All predecessors are computed, and termination guaranteed But: we might be adding non-predecessors R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

true/y := 0 y = 1 / id x < 1 / id x < 1 / id y < 1 / y := 0 x > 1 / id true/x, y := x+?, y+? true/x, y := x+?, y+? true/x, y := x+?, y+? true/x, y := x+?, y+?

Fortunately: correct if initial states have no incoming arcs.

56

slide-58
SLIDE 58

But does it work . . . ?

All predecessors are computed, and termination guaranteed But: we might be adding non-predecessors R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 l0 l0 l1 l1

Fortunately: correct if initial states have no incoming arcs.

57

slide-59
SLIDE 59

But does it work . . . ?

All predecessors are computed, and termination guaranteed But: we might be adding non-predecessors R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 l0 l0 l1 l1

Fortunately: correct if initial states have no incoming arcs.

58

slide-60
SLIDE 60

But does it work . . . ?

All predecessors are computed, and termination guaranteed But: we might be adding non-predecessors R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 l0 l0 l1 l1 l0

Fortunately: correct if initial states have no incoming arcs.

59

slide-61
SLIDE 61

But does it work . . . ?

All predecessors are computed, and termination guaranteed But: we might be adding non-predecessors R = { g0 l0 → g0 , g1 l1 → g0 , g1 l1 → g1 l1 l0 }

g0 g1 l0 l0 l1 l1 l0

Fortunately: correct if initial states have no incoming arcs.

60

slide-62
SLIDE 62

Forward search and complexity

Symbolic forward search with regular sets can be accelerated in a similar way Recall input: Alphabet Σ = G ∪ L, set R of rules, NFA A = (Q, L, →0, G, F) recognizing subset of G L∗. Complexity of backward search: O(|Q|2 · |R|) time, O(|Q| · |R| + | →0 |) space. Complexity of forward search: O(|G| · |R| · (|Q \ G| + |R|) + |G| · | →0 |) time and space.

61

slide-63
SLIDE 63

Reachable configurations of the plotter program

q q, m0 q, s0 q, u0 q, d0 q, r0 up0 down0 right0

  • m0. . .m7
  • s0. . .s5

, main1 main0 s5 m4 m0,m1 main0 s4 s1 s1 m1 r5

62

slide-64
SLIDE 64

Repeated reachability for prefix rewriting

Let I = g0 l0 and D = g L∗. D can be repeatedly reached from I iff g0 l0 − →∗ g′ l w and g′ l − →∗ g v − →∗ g′ l u for some g′, l, w, v, u. Repeated reachability can be reduced to computing several pre∗.

63