compositional recurrence analysis
play

Compositional Recurrence Analysis Azadeh Farzan Zachary Kincaid - PowerPoint PPT Presentation

Compositional Recurrence Analysis Azadeh Farzan Zachary Kincaid University of Toronto September 28, 2015 Compositional program analysis P P Break program into parts P P Analyze each part P P Compose the results Incremental analysis


  1. Compositional Recurrence Analysis Azadeh Farzan Zachary Kincaid University of Toronto September 28, 2015

  2. Compositional program analysis P P Break program into parts P P Analyze each part P P Compose the results Incremental analysis Compute in parallel P 1 ; P 2

  3. Compositional program analysis Break program into parts P P Analyze each part P P Compose the results Incremental analysis Compute in parallel P 1 ; P 2 P 1 P 2

  4. Compositional program analysis Break program into parts Analyze each part P P Compose the results Incremental analysis Compute in parallel P 1 ; P 2 P 1 P 2 � P 1 � � P 2 �

  5. Compositional program analysis Break program into parts Analyze each part Compose the results Incremental analysis Compute in parallel P 1 ; P 2 P 1 P 2 � P 1 � � P 2 � ⊙ � P 1 ; P 2 �

  6. Compositional program analysis Break program into parts Analyze each part Compose the results Incremental analysis Compute in parallel P 1 ; P 2 P 1 P 2 � P 1 � � P 2 � ⊙ � P 1 ; P 2 �

  7. Compositional program analysis Break program into parts Analyze each part Compose the results Incremental analysis Compute in parallel P 1 ; P 2 P 1 P 2 � P 1 � � P 2 � ⊙ � P 1 ; P 2 �

  8. Context n x x k n x k k x c x := 0 100 1 100 assert (x == n) x := x + c while (x < n): n := 100 c := 1 kc

  9. Context n x x k n x k k x c x := 0 100 1 100 assert (x == n) x := x + c while (x < n): n := 100 c := 1 kc

  10. Context k x x k n x k 100 x := 0 1 100 assert (x == n) x := x + c while (x < n): n := 100 c := 1 kc c = 1 ∧ n = 100 ∧ 0 ≤ x ≤ 100

  11. Context x := 0 c := 1 n := 100 while (x < n): x := x + c assert (x == n) 100 1 100 c n x ∃ k . (( k ≥ 1 ∧ x < n ) ∨ k = 0) ∧ x ′ = x + kc ...

  12. How can we analyze programs compositionally and precisely?

  13. x k x k x k y k y k y k Recurrence Analysis Loop abstraction: y y k x x k k k k y while (*): x Closed forms: Recurrences: y := y - 2 x := x + 1 k

  14. x k y k y y y k x x k k Loop abstraction: k Recurrence Analysis while (*): k x Closed forms: Recurrences: y := y - 2 x := x + 1 k x ( k ) = x ( k − 1) + 1 y ( k ) = y ( k − 1) − 2

  15. Recurrence Analysis Loop abstraction: y y k x x k k k while (*): Closed forms: Recurrences: y := y - 2 x := x + 1 x ( k ) = x ( k − 1) + 1 x ( k ) = x (0) + 1 k y ( k ) = y ( k − 1) − 2 y ( k ) = y (0) − 2 k

  16. Recurrence Analysis while (*): x := x + 1 y := y - 2 Recurrences: Closed forms: Loop abstraction: x ( k ) = x ( k − 1) + 1 x ( k ) = x (0) + 1 k y ( k ) = y ( k − 1) − 2 y ( k ) = y (0) − 2 k ∃ k . k ≥ 0 ∧ x ′ = x + k ∧ y ′ = y − 2 k

  17. while (z < 100): x := 0 y := 0 while (x + y < 10): z := z + 1 if (*): x := x + rand(1,3) else y := y + 1 w := w + x

  18. while (z < 100): x := 0 y := 0 while (x + y < 10): z := z + 1 if (*): x := x + rand(1,3) else y := y + 1 w := w + x

  19. How can we use recurrence analysis to compute approximations of arbitrary programs?

  20. Compositional Recurrence Analysis

  21. Algebraic Program Analysis [Tarjan ’81] 1 Compute a path expression to a point of interest (e.g., an assertion) 2 Evaluate the path expression in the semantic algebra defining the analysis

  22. outer: (h+g)i [x > 100] a b c d e f g h h+g ((h+g)ij) [j >= n] (h+g)ik i j k def((h+g)ij) (h+g)ik l m abc(def((h+g)ij) (h+g)ik) lm Path expression : Regular expression over alphabet of [i >= n] [j < n] inner: j := j + 1 end: x := 0 n := 10 i := 0 if (i >= n): goto end i := i + 1 j := 0 if (*): x := x + 1 if (j < n): j := j + 1 goto inner goto outer assert (x <= 100) x := 0 n := 10 i := 0 [i < n] i := i + 1 j := 0 x := x + 1 skip control flow edges

  23. outer: (h+g)i [x > 100] a b c d e f g h h+g ((h+g)ij) [j >= n] (h+g)ik i j k def((h+g)ij) (h+g)ik l m abc(def((h+g)ij) (h+g)ik) lm Path expression : Regular expression over alphabet of [i >= n] [j < n] inner: j := j + 1 end: x := 0 n := 10 i := 0 if (i >= n): goto end i := i + 1 j := 0 if (*): x := x + 1 if (j < n): j := j + 1 goto inner goto outer assert (x <= 100) x := 0 n := 10 i := 0 [i < n] i := i + 1 j := 0 x := x + 1 skip control flow edges

  24. outer: (h+g)i [x > 100] a b c d e f g h h+g ((h+g)ij) [j >= n] (h+g)ik i j k def((h+g)ij) (h+g)ik l m abc(def((h+g)ij) (h+g)ik) lm Path expression : Regular expression over alphabet of [i >= n] [j < n] inner: j := j + 1 end: x := 0 n := 10 i := 0 if (i >= n): goto end i := i + 1 j := 0 if (*): x := x + 1 if (j < n): j := j + 1 goto inner goto outer assert (x <= 100) x := 0 n := 10 i := 0 [i < n] i := i + 1 j := 0 x := x + 1 skip control flow edges

  25. outer: (h+g)i [x > 100] a b c d e f g h h+g ((h+g)ij) [j >= n] (h+g)ik i j k def((h+g)ij) (h+g)ik l m abc(def((h+g)ij) (h+g)ik) lm Path expression : Regular expression over alphabet of [i >= n] [j < n] inner: j := j + 1 end: x := 0 n := 10 i := 0 if (i >= n): goto end i := i + 1 j := 0 if (*): x := x + 1 if (j < n): j := j + 1 goto inner goto outer assert (x <= 100) x := 0 n := 10 i := 0 [i < n] i := i + 1 j := 0 x := x + 1 skip control flow edges

  26. outer: (h+g)i [x > 100] a b c d e f g h h+g ((h+g)ij) [j >= n] (h+g)ik i j k def((h+g)ij) (h+g)ik l m abc(def((h+g)ij) (h+g)ik) lm Path expression : Regular expression over alphabet of [i >= n] [j < n] inner: j := j + 1 end: x := 0 n := 10 i := 0 if (i >= n): goto end i := i + 1 j := 0 if (*): x := x + 1 if (j < n): j := j + 1 goto inner goto outer assert (x <= 100) x := 0 n := 10 i := 0 [i < n] i := i + 1 j := 0 x := x + 1 skip control flow edges

  27. outer: (h+g)i [x > 100] a b c d e f g h h+g ((h+g)ij) [j >= n] (h+g)ik i j k def((h+g)ij) (h+g)ik l m abc(def((h+g)ij) (h+g)ik) lm Path expression : Regular expression over alphabet of [i >= n] [j < n] inner: j := j + 1 end: x := 0 n := 10 i := 0 if (i >= n): goto end i := i + 1 j := 0 if (*): x := x + 1 if (j < n): j := j + 1 goto inner goto outer assert (x <= 100) x := 0 n := 10 i := 0 [i < n] i := i + 1 j := 0 x := x + 1 skip control flow edges

  28. outer: h+g [i >= n] [x > 100] a b c d e f g h (h+g)i inner: ((h+g)ij) (h+g)ik i j k l m abc(def((h+g)ij) (h+g)ik) lm Path expression : Regular expression over alphabet of [j >= n] [j < n] j := j + 1 skip end: x := 0 n := 10 i := 0 if (i >= n): goto end i := i + 1 j := 0 if (*): x := x + 1 j := j + 1 if (j < n): goto inner goto outer assert (x <= 100) x := 0 n := 10 i := 0 [i < n] i := i + 1 j := 0 x := x + 1 control flow edges def((h+g)ij) ∗ (h+g)ik

  29. outer: h+g [i >= n] [x > 100] a b c d e f g h (h+g)i inner: ((h+g)ij) (h+g)ik i j k def((h+g)ij) (h+g)ik l m Path expression : Regular expression over alphabet of [j >= n] [j < n] j := j + 1 skip end: x := 0 n := 10 i := 0 if (i >= n): goto end i := i + 1 j := 0 if (*): x := x + 1 j := j + 1 if (j < n): goto inner goto outer assert (x <= 100) x := 0 n := 10 i := 0 [i < n] i := i + 1 j := 0 x := x + 1 control flow edges abc(def((h+g)ij) ∗ (h+g)ik) ∗ lm

  30. • Control flow edges D is a semantic function Program meanings Composition operators Interpretation : I = ⟨D , � · � ⟩ • D = ⟨ D , ⊙ , ⊕ , ⍟ , 0 , 1 ⟩ is a semantic algebra

  31. • Control flow edges D is a semantic function Program meanings Composition operators Interpretation : I = ⟨D , � · � ⟩ • D = ⟨ D , ⊙ , ⊕ , ⍟ , 0 , 1 ⟩ is a semantic algebra

  32. • Control flow edges D is a semantic function Program meanings Composition operators Interpretation : I = ⟨D , � · � ⟩ � �� � • D = ⟨ D , ⊙ , ⊕ , ⍟ , 0 , 1 ⟩ is a semantic algebra

  33. Program meanings Composition operators Interpretation : I = ⟨D , � · � ⟩ • D = ⟨ D , ⊙ , ⊕ , ⍟ , 0 , 1 ⟩ is a semantic algebra • � · � : Control flow edges → D is a semantic function

  34. Program meanings Composition operators Interpretation : I = ⟨D , � · � ⟩ • D = ⟨ D , ⊙ , ⊕ , ⍟ , 0 , 1 ⟩ is a semantic algebra • � · � : Control flow edges → D is a semantic function � abc(def((h+g)ij) ∗ (h+g)ik) ∗ lm � = � a � ⊙ � b � ⊙ � c � ( ⊙ � d � ⊙ � e � ⊙ � f � ( ) ⍟ ⊙ ( � h � ⊕ � g � ) ⊙ � i � ⊙ � j � ) ⍟ ⊙ ( � h � ⊕ � g � ) ⊙ � i � ⊙ � k � ⊙ � l � ⊙ � m �

  35. Program meanings Composition operators Compositional Recurrence Analysis • x x x x x • • Interpretation : I = ⟨D , � · � ⟩ • D = ⟨ D , ⊙ , ⊕ , ⍟ , 0 , 1 ⟩ is a semantic algebra • � · � : Control flow edges → D is a semantic function • D : set of arithmetic transition formulas � x := x + 1 � ≜ x ′ = x + 1 ∧ y ′ = y ∧ i ′ = i ∧ j ′ = j ∧ n ′ = n

Recommend


More recommend