Strongest postcondition rules

Slides:



Advertisements
Similar presentations
Program Verification Using Hoares Logic Book: Chapter 7.
Advertisements

Program verification: flowchart programs Book: chapter 7.
Semantics Static semantics Dynamic semantics attribute grammars
Program Analysis and Verification
ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Reasoning About Code; Hoare Logic, continued
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
50.530: Software Engineering Sun Jun SUTD. Week 9: Hoare Logic.
David Evans CS655: Programming Languages University of Virginia Computer Science Lecture 19: Minding Ps & Qs: Axiomatic.
Partial correctness © Marcelo d’Amorim 2010.
Predicate Transformers
Program Proving Notes Ellen L. Walker.
Duminda WijesekeraSWSE Program Correctness1 SWSE 623 Program Correctness -Pre-condition, Post-conditions and Loop invariants.
Program Analysis and Verification Spring 2014 Program Analysis and Verification Lecture 5: Axiomatic Semantics II Roman Manevich Ben-Gurion University.
Denotational Semantics Syntax-directed approach, generalization of attribute grammars: –Define context-free abstract syntax –Specify syntactic categories.
1 CS100J October 06, 2005 For Loops Reading: Secs Quote for the Day: Perhaps the most valuable result of all education is the ability to make yourself.
Hoare-style program verification K. Rustan M. Leino Guest lecturer Rob DeLine’s CSE 503, Software Engineering University of Washington 26 Apr 2004.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Software Verification Bertrand Meyer Chair of Software Engineering Lecture 2: Axiomatic semantics.
Floyd Hoare Logic. Semantics A programming language specification consists of a syntactic description and a semantic description. Syntactic description:symbols.
Proving Program Correctness The Axiomatic Approach.
Proving Program Correctness The Axiomatic Approach.
Program Analysis and Verification Noam Rinetzky Lecture 3: Axiomatic Semantics 1 Slides credit: Roman Manevich, Mooly Sagiv, Eran Yahav.
Program Analysis and Verification
Program Analysis and Verification Spring 2014 Program Analysis and Verification Lecture 7: Static Analysis I Roman Manevich Ben-Gurion University.
Software Verification 1 Deductive Verification Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt Universität und Fraunhofer Institut.
Program Analysis and Verification
Program Analysis and Verification Spring 2014 Program Analysis and Verification Lecture 4: Axiomatic Semantics I Roman Manevich Ben-Gurion University.
10.3: rational exponents April 27, Objectives 1.Define rational exponents 2.Simplify expressions that contain rational exponents 3.Estimate the.
Example of a Worked-out Proof. Consider again this program Let 0  n. This program checks if all elements of the segment a[0..n) are zero. {* 0  n *}
6.8 Graphing the Absolute Value. 6.8 – Graphing Absolute Value Goals / “I can…”  Translate the graph of an absolute value equation.
Cs7100(Prasad)L18-9WP1 Axiomatic Semantics Predicate Transformers.
1 Section 8.2 Program Correctness (for imperative programs) A theory of program correctness needs wffs, axioms, and inference rules. Wffs (called Hoare.
Program Analysis and Verification Spring 2014 Program Analysis and Verification Lecture 6: Axiomatic Semantics III Roman Manevich Ben-Gurion University.
Program Analysis and Verification Spring 2015 Program Analysis and Verification Lecture 6: Axiomatic Semantics III Roman Manevich Ben-Gurion University.
T/F  The following code will compile without error. int x = 3, y = 4, z = 5; double k = 3.4; cout
Program Analysis and Verification Spring 2016 Program Analysis and Verification Lecture 5: Axiomatic Semantics II Roman Manevich Ben-Gurion University.
11/22/2016IT 3271 A formal system:Axioms and Rules, for inferring valid specification x := m; y := n; while ¬(x=y) do if x>y then x := x-y else y := y-x.
Spring 2017 Program Analysis and Verification
Math/CSE 1019C: Discrete Mathematics for Computer Science Fall 2012
Spring 2017 Program Analysis and Verification
Spring 2016 Program Analysis and Verification
Warm-up exercises Define program state: Define state predicate:
Proving Loops Testing debugging and verification
Program Analysis and Verification
Spring 2016 Program Analysis and Verification
Hoare-style program verification
Predicate Transforms I
Lecture 2: Axiomatic semantics
Program Analysis and Verification
Programming Languages and Compilers (CS 421)
Programming Languages 2nd edition Tucker and Noonan
Example of a Worked-out Proof
Predicate Transformers
Formal Methods in software development
Output Variables {true} S {i = j} i := j; or j := i;
Spring 2016 Program Analysis and Verification
Predicate Transforms I
Binary Search and Loop invariants
PZ03D - Program verification
PZ03D - Program verification
Asymptotic complexity
Program Verification with Hoare Logic
Lecture 2: Axiomatic semantics
CIS 720 Lecture 3.
Programming Languages and Compilers (CS 421)
CIS 720 Lecture 3.
Programming Languages 2nd edition Tucker and Noonan
COP4020 Programming Languages
Presentation transcript:

Strongest postcondition rules sp(skip, P) = P sp(x := a, P) = v. x=a[v/x]  P[v/x] sp(S1; S2, P) = sp(S2, sp(S1, P)) sp(if b then S1 else S2, P) = sp(S1, b  P)  sp(S2, b  P) sp(while b do {} S, P) =   b where {b  } S {} and P  b   Inv  ((Inv  b)  wp(S, Inv))  ((Inv  b)  Q) Parameterized by the loop invariant Inv

Exponentiation prog. – prove Background axioms: { } t := 0; { } res := 1; { } Inv = { } while (t < y) do { } { } res := res * x; { } t := t + 1; { } { } { }

Small array update rules (sp) [array-loadF] { a=b } x := y[a] { x=y(b) } In both rules v, g, and b are fresh [array-updateF] { y=g  a=b } y[a] := x { y=g[bx] } same as [array-updateF] { y=g  a=b } y := y[ax] { y=g[bx] }

Rewrite assignment as function update b[i] := a[j]

Calculate the postcondition 2 { ob=b  a(j)=x  z.0z<i  ob(z)=x } b := b[ia(j)] { }

Array-max program – specify nums : array N : int // N stands for num’s length { N0  nums=orig_nums } x := 0 res := nums[0] Inv = { } while x < N if nums[x] > res then res := nums[x] x := x + 1 { x=N } { m. (m0  m<N)  nums(m)res } { m. m0  m<N  nums(m)=res } { nums=orig_nums }

Array-max program – specify nums : array N : int // N stands for num’s length { N0 } x := 0 res := nums[0] while x < N if nums[x] > res then res := nums[x] x := x + 1

Total correctness semantics for While [ P[a/x] ] x := a [ P ] [assp] [ P ] skip [ P ] [skipp] [ P ] S1 [ Q ], [ Q ] S2 [ R ] [ P ] S1; S2 [ R ] [compp] [ b  P ] S1 [ Q ], [ b  P ] S2 [ Q ] [ P ] if b then S1 else S2 [ Q ] [ifp] [whilep] [ b  P  t=k ] S [ P  t<k ] [ P ] while b do S [ b  P ] P  t0 [ P’ ] S [ Q’ ] [ P ] S [ Q ] [consp] if PP’ and Q’Q

Two counters [ ] b := 0; Variant = [ ] while (x0  y0) do b := 1−b; if (b) x := x−1 else y := y−1 [ true ]

Slow countdown: find variant [ true ] flag := 0; Variant = [ ] while (x>0) do flag := 1−flag; if flag=0 then x := x−1 [ true ]