numerical computations and formal methods
play

Numerical Computations and Formal Methods Guillaume Melquiond - PowerPoint PPT Presentation

Program verification Formal arithmetic Decision procedures Numerical Computations and Formal Methods Guillaume Melquiond Proval, Laboratoire de Recherche en Informatique INRIA SaclayIdF, Universit e Paris Sud, CNRS October 28, 2009


  1. Program verification Formal arithmetic Decision procedures Numerical Computations and Formal Methods Guillaume Melquiond Proval, Laboratoire de Recherche en Informatique INRIA Saclay–IdF, Universit´ e Paris Sud, CNRS October 28, 2009 Guillaume Melquiond Numerical Computations and Formal Methods

  2. Program verification Formal arithmetic Decision procedures Numerical Computations and Formal Methods Deductive program verification 1 Computing in a formal system 2 Decision procedures for arithmetic theories 3 Conclusion 4 Guillaume Melquiond Numerical Computations and Formal Methods

  3. Program verification Formal arithmetic Decision procedures WP Why Gappa Deductive Program Verification Deductive program verification 1 Floyd-Hoare logic and weakest preconditions A framework for program verification: Why Gappa Computing in a formal system 2 Decision procedures for arithmetic theories 3 Conclusion 4 Guillaume Melquiond Numerical Computations and Formal Methods

  4. Program verification Formal arithmetic Decision procedures WP Why Gappa Hoare Triple Definition (Hoare triple) { precondition } code { postcondition } . Meaning of correctness: If the precondition holds just before the code is executed, the postcondition holds just after it has been executed. Guillaume Melquiond Numerical Computations and Formal Methods

  5. Program verification Formal arithmetic Decision procedures WP Why Gappa Hoare Triple Definition (Hoare triple) { precondition } code { postcondition } . Meaning of correctness: If the precondition holds just before the code is executed, the postcondition holds just after it has been executed. Note: the definition assumes the code terminates. If it does not, any postcondition holds, including False. Guillaume Melquiond Numerical Computations and Formal Methods

  6. Program verification Formal arithmetic Decision procedures WP Why Gappa Hoare Triple 1 { x >= 0 } 2 y = floor(sqrt(x)) 3 { y >= 0 and y*y <= x < (y+1)*(y+1) } Guillaume Melquiond Numerical Computations and Formal Methods

  7. Program verification Formal arithmetic Decision procedures WP Why Gappa Weakest Precondition Definition (Weakest precondition) R is the weakest precondition of a code C and a postcondition Q iff any correct triple { P } C { Q } satisfies P ⇒ R . Guillaume Melquiond Numerical Computations and Formal Methods

  8. Program verification Formal arithmetic Decision procedures WP Why Gappa Weakest Precondition Definition (Weakest precondition) R is the weakest precondition of a code C and a postcondition Q iff any correct triple { P } C { Q } satisfies P ⇒ R . A function behaves correctly (modulo termination) if its specification can be expressed as a correct triple. Guillaume Melquiond Numerical Computations and Formal Methods

  9. Program verification Formal arithmetic Decision procedures WP Why Gappa Weakest Precondition Definition (Weakest precondition) R is the weakest precondition of a code C and a postcondition Q iff any correct triple { P } C { Q } satisfies P ⇒ R . A function behaves correctly (modulo termination) if its specification can be expressed as a correct triple. How to verify it? Compute the weakest precondition (Dijkstra, 1975) from the function and its specified postcondition. Prove that the specified precondition implies the weakest one. Guillaume Melquiond Numerical Computations and Formal Methods

  10. Program verification Formal arithmetic Decision procedures WP Why Gappa A Framework for Program Verification: Why Why is a minimal system: small ML-like programming language, small specification language. Guillaume Melquiond Numerical Computations and Formal Methods

  11. Program verification Formal arithmetic Decision procedures WP Why Gappa A Framework for Program Verification: Why Why is a minimal system: small ML-like programming language, small specification language. Why is an intermediate environment: it computes weakest preconditions; it generates VCs for provers, interactive or not. Guillaume Melquiond Numerical Computations and Formal Methods

  12. Program verification Formal arithmetic Decision procedures WP Why Gappa A Framework for Program Verification: Why Why is a minimal system: small ML-like programming language, small specification language. Why is an intermediate environment: it computes weakest preconditions; it generates VCs for provers, interactive or not. Various tools translate programing languages (C, Java) to the ML language. Guillaume Melquiond Numerical Computations and Formal Methods

  13. Program verification Formal arithmetic Decision procedures WP Why Gappa Environment annotated annotated Java/JML prog. C program Frama-C ML program Krakatoa Caduceus Jessie Why Interactive provers Automated provers Coq PVS Alt-Ergo SMT-lib (Yices, Z3, CVC3) Isabelle Mizar Simplify HOL4 Harvey Zenon Gappa HOL light Guillaume Melquiond Numerical Computations and Formal Methods

  14. Program verification Formal arithmetic Decision procedures WP Why Gappa Toy Example: Cosine Around Zero 1 /*@ requires \abs(x) <= 0x1p -5 ; @ ensures \abs(\ result - \cos(x)) <= 0x1p -23; */ 2 3 float toy_cos(float x) { // @assert \abs (1.0-x*x*0.5 - \cos(x)) <= 0x1p -24; 4 return 1.0f - x * x * 0.5f; 5 6 } “ \result ” is the value returned by the function, that is: 1 − 0 . 5 · x 2 with all the operations rounded to nearest binary32. Safety: none of the operations overflow nor are invalid. Correctness: the result is almost the mathematical cosine. Guillaume Melquiond Numerical Computations and Formal Methods

  15. Program verification Formal arithmetic Decision procedures WP Why Gappa Frama-C/Jessie/Why + Gappa Guillaume Melquiond Numerical Computations and Formal Methods

  16. Program verification Formal arithmetic Decision procedures WP Why Gappa Verifying Arithmetic Properties Kind of properties: Precondition validity: no overflow: ∀ � x , f ( � x ) ∈ D ; Guillaume Melquiond Numerical Computations and Formal Methods

  17. Program verification Formal arithmetic Decision procedures WP Why Gappa Verifying Arithmetic Properties Kind of properties: Precondition validity: no overflow: ∀ � x , f ( � x ) ∈ D ; no domain error: ∀ � x , d ( f ( � x ) , g ( � x ) , · · · ) ∈ D . Guillaume Melquiond Numerical Computations and Formal Methods

  18. Program verification Formal arithmetic Decision procedures WP Why Gappa Verifying Arithmetic Properties Kind of properties: Precondition validity: no overflow: ∀ � x , f ( � x ) ∈ D ; no domain error: ∀ � x , d ( f ( � x ) , g ( � x ) , · · · ) ∈ D . Accuracy of results: absolute error: ∀ � x , f ( � x ) − g ( � x ) ∈ E ; Guillaume Melquiond Numerical Computations and Formal Methods

  19. Program verification Formal arithmetic Decision procedures WP Why Gappa Verifying Arithmetic Properties Kind of properties: Precondition validity: no overflow: ∀ � x , f ( � x ) ∈ D ; no domain error: ∀ � x , d ( f ( � x ) , g ( � x ) , · · · ) ∈ D . Accuracy of results: absolute error: ∀ � x , f ( � x ) − g ( � x ) ∈ E ; relative error: ∀ � x , ∃ ε, f ( � x ) = g ( � x ) × (1 + ε ). Guillaume Melquiond Numerical Computations and Formal Methods

  20. Program verification Formal arithmetic Decision procedures WP Why Gappa Verifying Arithmetic Properties Kind of properties: Precondition validity: no overflow: ∀ � x , f ( � x ) ∈ D ; no domain error: ∀ � x , d ( f ( � x ) , g ( � x ) , · · · ) ∈ D . Accuracy of results: absolute error: ∀ � x , f ( � x ) − g ( � x ) ∈ E ; relative error: ∀ � x , ∃ ε, f ( � x ) = g ( � x ) × (1 + ε ). Language of formulas: intervals with nonsymbolic bounds, expressions with mathematical operators (e.g., × , tan) and rounding operators (e.g., ⌊·⌋ ). Guillaume Melquiond Numerical Computations and Formal Methods

  21. Program verification Formal arithmetic Decision procedures WP Why Gappa Gappa Input: logical formula about expressions on real numbers. Output: “Yes” and a formal proof, or ”I don’t know”. Guillaume Melquiond Numerical Computations and Formal Methods

  22. Program verification Formal arithmetic Decision procedures WP Why Gappa Gappa Input: logical formula about expressions on real numbers. Output: “Yes” and a formal proof, or ”I don’t know”. Method: saturation over a set of theorems. Naive interval arithmetic: u ∈ [ u , u ] ∧ v ∈ [ v , v ] ⇒ u + v ∈ [ u + v , u + v ]. Guillaume Melquiond Numerical Computations and Formal Methods

  23. Program verification Formal arithmetic Decision procedures WP Why Gappa Gappa Input: logical formula about expressions on real numbers. Output: “Yes” and a formal proof, or ”I don’t know”. Method: saturation over a set of theorems. Naive interval arithmetic: u ∈ [ u , u ] ∧ v ∈ [ v , v ] ⇒ u + v ∈ [ u + v , u + v ]. Floating-/fixed-point arithmetic properties: u ∈ 2 − 1074 · Z ⇒ ∃ ε ∈ [ − 2 − 53 , 2 − 53 ] , ◦ ( u ) = u × (1 + ε ). Guillaume Melquiond Numerical Computations and Formal Methods

Recommend


More recommend