bound analysis of imperative programs with the size
play

Bound Analysis of Imperative Programs with the Size change - PowerPoint PPT Presentation

Bound Analysis of Imperative Programs with the Size change Abstraction Florian Zuleger, TU Vienna SAS, Venice, 16.09.2011 Joint work with Sumit Gulwani, Microsoft Research Moritz Sinn, Helmut Veith, TU Vienna Resource Bounds Programs consume a


  1. Bound Analysis of Imperative Programs with the Size ‐ change Abstraction Florian Zuleger, TU Vienna SAS, Venice, 16.09.2011 Joint work with Sumit Gulwani, Microsoft Research Moritz Sinn, Helmut Veith, TU Vienna

  2. Resource Bounds Programs consume a variety of resources: – CPU time, memory, network bandwidth, power Bounding the use of such resources is important: – Economic incentives – Better user experience – Hard constraints on availability of resources Program correctness depends on bounding quantitative properties of data: – Information leakage, Propagation of numerical errors

  3. The Reachability ‐ bound Problem (Gulwani, Zuleger, PLDI 2010) void main (int n, C[] temp) { Given a control int i := 0; while (i < n) { location l inside int j := i+1; a program P. while (j < n) { if (nondet()) { l : temp[n] := new C(); How often can l be j--; n--; } j++; } visited inside P? i++; } } Goal: A symbolic bound Bound( l ) in terms of the inputs of P.

  4. Bound Computation and Termination A bound for a loop implies the termination of the loop. ⇒ Computing bounds is more difficult than proving termination! Can successfull techniques for termination analysis be extended to bound analysis? What about • Size ‐ change Abstraction (Ben ‐ Amram, Lee, Jones, 2001) Yes! • Transition Invariants (Podelski, Rybalchenko, 2004)? Not so easy...

  5. Outline 1. Introduction 2. Comparing SCA with Transition Invariants 3. SCA solves Technical Challanges 4. How to apply SCA on Imperative Programs

  6. Size ‐ change Abstraction (SCA) void main (int n) { l int x=n; int y=n; l : while (x>0 Æ y>0) { ρ 1 if (nondet()) ρ 2 x--; else ρ 1 ≡ x > 0 Æ y > 0 Æ x ‐ 1 = x‘ Æ y = y‘ y--; ρ 2 ≡ x > 0 Æ y > 0 Æ x = x‘ Æ y ‐ 1 = y‘ }

  7. Size ‐ change Abstraction (SCA) void main (int n) { l int x=n; int y=n; l : while (x>0 Æ y>0) { α ( ρ 1 ) if (nondet()) α ( ρ 2 ) x--; else α ( ρ 1 ) ≡ x > 0 Æ y > 0 Æ x > x‘ Æ y = y‘ y--; α ( ρ 2 ) ≡ x > 0 Æ y > 0 Æ x = x‘ Æ y > y‘ } Predicate abstract domain consisting of inequalities between integer variables (primed and unprimed)

  8. Size ‐ change Abstraction (SCA) void main (int n) { l int x=n; int y=n; l : while (x>0 Æ y>0) { α ( ρ 1 ) if (nondet()) α ( ρ 2 ) x--; else α ( ρ 1 ) ≡ x > 0 Æ y > 0 Æ x > x‘ Æ y = y‘ y--; α ( ρ 2 ) ≡ x > 0 Æ y > 0 Æ x = x‘ Æ y > y‘ } Finite powerset abstract domain whose base elements are conjuncts of inequalities between integer variables (primed and unprimed)

  9. Size ‐ change Abstraction (SCA) void main (int n) { l int x=n; int y=n; l : while (x>0 Æ y>0) { α ( ρ 1 ) if (nondet()) α ( ρ 2 ) x--; else = = 0 0’ 0 0’ y--; > = x x’ x x’ α ( ρ 2 ) ≡ α ( ρ 1 ) ≡ < < } > = y y’ y y’ < < Control flow graph whose edges are labeled by size ‐ change graphs

  10. SCA is a Success Story • Termination is decidable in PSPACE (Ben ‐ Amram, Lee, Jones, 2001; Ben ‐ Amram,2011) • Complete method for extracting ranking functions on terminating instances (possibly exponentially large) • SCA based termination analysis is implemented in widely ‐ used systems such as ACL2, Isabelle, AProVE • The industrial ‐ strength tool ACL2 can automatically prove the termination of 98% of the functions in its database

  11. Good Computational Properties • Enjoys built ‐ in disjunction. • Transitive hulls can be computed without overapproximation techniques such as widening. • Transitive hulls preserve termination. • Abstraction can be done by SMT solver calls. ⇒ Potential for automation

  12. Transition Invariants • Have been developed as adaption of SCA to imperative programs • Experimentally proven useful on device drivers in the Terminator tool; see Cook et al. 2006 • More general than SCA; for formal comparison see Heizmann et al. 2011

  13. Transition Invariants void main (int n) { l int x=n; int y=n; l : while (x>0 Æ y>0) { ρ 1 if (nondet()) ρ 2 x--; else ρ 1 ≡ x > 0 Æ y > 0 Æ x ‐ 1 = x‘ Æ y = y‘ y--; ρ 2 ≡ x > 0 Æ y > 0 Æ x = x‘ Æ y ‐ 1 = y‘ } Termination proof: ( ρ 1 ∪ ρ 2 ) + ⊆ T 1 ∪ T 2 , where T 1 ≡ x > 0 Æ x‘ = x ‐ 1 and T 2 ≡ y > 0 Æ y‘ = y ‐ 1

  14. Transition Invariants void main (int n) { l int x=n; int y=n; l : while (x>0 Æ y>0) { ρ 1 if (nondet()) ρ 2 x--; else Well ‐ founded ρ 1 ≡ x > 0 Æ y > 0 Æ x ‐ 1 = x‘ Æ y = y‘ y--; relations ρ 2 ≡ x > 0 Æ y > 0 Æ x = x‘ Æ y ‐ 1 = y‘ } Termination proof: ( ρ 1 ∪ ρ 2 ) + ⊆ T 1 ∪ T 2 , where T 1 ≡ x > 0 Æ x‘ = x ‐ 1 and T 2 ≡ y > 0 Æ y‘ = y ‐ 1

  15. Transition Invariants void main (int n) { l int x=n; int y=n; l : while (x>0 Æ y>0) { ρ 1 if (nondet()) ρ 2 x--; x and y are else Well ‐ founded local ranking ρ 1 ≡ x > 0 Æ y > 0 Æ x ‐ 1 = x‘ Æ y = y‘ y--; relations ρ 2 ≡ x > 0 Æ y > 0 Æ x = x‘ Æ y ‐ 1 = y‘ functions } Termination proof: ( ρ 1 ∪ ρ 2 ) + ⊆ T 1 ∪ T 2 , where T 1 ≡ x > 0 Æ x‘ = x ‐ 1 and T 2 ≡ y > 0 Æ y‘ = y ‐ 1

  16. Transition Invariants void main (int n) { l int x=n; int y=n; Transitive hull l : while (x>0 Æ y>0) { ρ 1 in the concrete if (nondet()) ρ 2 x--; x and y are else Well ‐ founded local ranking ρ 1 ≡ x > 0 Æ y > 0 Æ x ‐ 1 = x‘ Æ y = y‘ y--; relations ρ 2 ≡ x > 0 Æ y > 0 Æ x = x‘ Æ y ‐ 1 = y‘ functions } Termination proof: ( ρ 1 ∪ ρ 2 ) + ⊆ T 1 ∪ T 2 , where T 1 ≡ x > 0 Æ x‘ = x ‐ 1 and T 2 ≡ y > 0 Æ y‘ = y ‐ 1

  17. Transition Invariants void main (int n) { l int x=n; int y=n; l : while (x>0 Æ y>0) { ρ 1 if (nondet()) ρ 2 x--; else { ρ 1 ≡ x > 0 Æ y > 0 Æ x ‐ 1 = x‘ Æ y = y‘ x := n; ρ 2 ≡ x > 0 Æ y > 0 Æ n = x‘ Æ y ‐ 1 = y‘ y--; } } Termination proof: ( ρ 1 ∪ ρ 2 ) + ⊆ T 1 ∪ T 2 , where T 1 ≡ x > 0 Æ x‘ = x ‐ 1 and T 2 ≡ y > 0 Æ y‘ = y ‐ 1

  18. Transition Invariants void main (int n) { l We reset int x=n; int y=n; l : while (x>0 Æ y>0) { x to n! ρ 1 if (nondet()) ρ 2 x--; else { ρ 1 ≡ x > 0 Æ y > 0 Æ x ‐ 1 = x‘ Æ y = y‘ x := n; ρ 2 ≡ x > 0 Æ y > 0 Æ n = x‘ Æ y ‐ 1 = y‘ y--; } } Termination proof: ( ρ 1 ∪ ρ 2 ) + ⊆ T 1 ∪ T 2 , where T 1 ≡ x > 0 Æ x‘ = x ‐ 1 and T 2 ≡ y > 0 Æ y‘ = y ‐ 1

  19. Transition Invariants void main (int n) { l We reset int x=n; int y=n; Same termination l : while (x>0 Æ y>0) { x to n! proof! ρ 1 if (nondet()) ρ 2 x--; else { ρ 1 ≡ x > 0 Æ y > 0 Æ x ‐ 1 = x‘ Æ y = y‘ x := n; ρ 2 ≡ x > 0 Æ y > 0 Æ n = x‘ Æ y ‐ 1 = y‘ y--; } } Termination proof: ( ρ 1 ∪ ρ 2 ) + ⊆ T 1 ∪ T 2 , where T 1 ≡ x > 0 Æ x‘ = x ‐ 1 and T 2 ≡ y > 0 Æ y‘ = y ‐ 1

  20. Transition Invariants void main (int n) { l We reset int x=n; int y=n; Same termination l : while (x>0 Æ y>0) { x to n! proof! ρ 1 if (nondet()) ρ 2 x--; else { ρ 1 ≡ x > 0 Æ y > 0 Æ x ‐ 1 = x‘ Æ y = y‘ x := n; ρ 2 ≡ x > 0 Æ y > 0 Æ n = x‘ Æ y ‐ 1 = y‘ y--; } } Termination proof: ( ρ 1 ∪ ρ 2 ) + ⊆ T 1 ∪ T 2 , where T 1 ≡ x > 0 Æ x‘ = x ‐ 1 and T 2 ≡ y > 0 Æ y‘ = y ‐ 1

  21. Size ‐ change Abstraction (SCA) void main (int n) { void main (int n) { int x=n; int y=n; int x=n; int y=n; l : while (x>0 Æ y>0) { l : while (x>0 Æ y>0) { if (nondet()) if (nondet()) x--; x--; else else { y--; x := n; } y--; } } α ( ρ 1 ) ≡ x > 0 Æ y > 0 α ( ρ 1 ) ≡ x > 0 Æ y > 0 Æ x > x‘ Æ y = y‘ Æ x > x‘ Æ y = y‘ α ( ρ 2 ) ≡ x > 0 Æ y > 0 α ( ρ 2 ) ≡ x > 0 Æ y > 0 Æ x = x‘ Æ y > y‘ Æ n = x‘ Æ y > y‘

  22. Size ‐ change Abstraction (SCA) void main (int n) { void main (int n) { int x=n; int y=n; int x=n; int y=n; l : while (x>0 Æ y>0) { l : while (x>0 Æ y>0) { if (nondet()) if (nondet()) x--; x--; else else { y--; x := n; } y--; } } α ( ρ 1 ) ≡ x > 0 Æ y > 0 α ( ρ 1 ) ≡ x > 0 Æ y > 0 Æ x > x‘ Æ y = y‘ Æ x > x‘ Æ y = y‘ α ( ρ 2 ) ≡ x > 0 Æ y > 0 α ( ρ 2 ) ≡ x > 0 Æ y > 0 Æ x = x‘ Æ y > y‘ Æ n = x‘ Æ y > y‘

  23. Bounds by SCA α ( ρ 1 ) ≡ x > 0 Æ y > 0 α ( ρ 1 ) ≡ x > 0 Æ y > 0 Æ x > x‘ Æ y = y‘ Æ x > x‘ Æ y = y‘ α ( ρ 2 ) ≡ x > 0 Æ y > 0 α ( ρ 2 ) ≡ x > 0 Æ y > 0 Æ x = x‘ Æ y > y‘ Æ n = x‘ Æ y > y‘ Our bound algorithm for SCA: uses only the abstracted transitions • discovers x and y as norms by heuristics • x and y stay constant on the only x is increased on respective other transition the other transition Our tool computes the Our tool computes the ranking function x+y, which ranking function (x,y), which results in Bound( l ) = 2n results in Bound( l ) = n 2

  24. Outline 1. Introduction 2. Comparing SCA with Transition Invariants 3. SCA solves Technical Challanges 4. How to apply SCA on Imperative Programs

  25. SCA solves Technical Challanges We do not use SCA because we like the formalism, but because we believe that SCA is the right abstraction for the bound analysis of imperative programs.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend