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 Compute in parallel P 1 ; P 2
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
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 �
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 �
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 �
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 �
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
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
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
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 ...
How can we analyze programs compositionally and precisely?
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
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
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
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
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
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
How can we use recurrence analysis to compute approximations of arbitrary programs?
Compositional Recurrence Analysis
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
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
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
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
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
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
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
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
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
• Control flow edges D is a semantic function Program meanings Composition operators Interpretation : I = ⟨D , � · � ⟩ • D = ⟨ D , ⊙ , ⊕ , ⍟ , 0 , 1 ⟩ is a semantic algebra
• Control flow edges D is a semantic function Program meanings Composition operators Interpretation : I = ⟨D , � · � ⟩ • D = ⟨ D , ⊙ , ⊕ , ⍟ , 0 , 1 ⟩ is a semantic algebra
• Control flow edges D is a semantic function Program meanings Composition operators Interpretation : I = ⟨D , � · � ⟩ � �� � • D = ⟨ D , ⊙ , ⊕ , ⍟ , 0 , 1 ⟩ is a semantic algebra
Program meanings Composition operators Interpretation : I = ⟨D , � · � ⟩ • D = ⟨ D , ⊙ , ⊕ , ⍟ , 0 , 1 ⟩ is a semantic algebra • � · � : Control flow edges → D is a semantic function
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 �
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