Partial correctness © Marcelo d’Amorim 2010.

Slides:



Advertisements
Similar presentations
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Advertisements

Semantics Static semantics Dynamic semantics attribute grammars
PZ03D Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03D - Program verification Programming Language Design.
Reasoning About Code; Hoare Logic, continued
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 13.
David Evans CS655: Programming Languages University of Virginia Computer Science Lecture 19: Minding Ps & Qs: Axiomatic.
Axiomatic Verification I Prepared by Stephen M. Thebaut, Ph.D. University of Florida Software Testing and Verification Lecture 17.
Axiomatic Semantics The meaning of a program is defined by a formal system that allows one to deduce true properties of that program. No specific meaning.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
Simple Example {i = 0} j := i * i {j < 100} Can we ‘verify’ this triple? Only if we know the semantics of assignment.
Predicate Transformers
Program Proving Notes Ellen L. Walker.
Fall Semantics Juan Carlos Guzmán CS 3123 Programming Languages Concepts Southern Polytechnic State University.
Duminda WijesekeraSWSE Program Correctness1 SWSE 623 Program Correctness -Pre-condition, Post-conditions and Loop invariants.
1 Semantic Description of Programming languages. 2 Static versus Dynamic Semantics n Static Semantics represents legal forms of programs that cannot be.
1/22 Programs : Semantics and Verification Charngki PSWLAB Programs: Semantics and Verification Mordechai Ben-Ari Mathematical Logic for Computer.
CS 355 – Programming Languages
ESC Java. Static Analysis Spectrum Power Cost Type checking Data-flow analysis Model checking Program verification AutomatedManual ESC.
Hoare-style program verification K. Rustan M. Leino Guest lecturer Rob DeLine’s CSE 503, Software Engineering University of Washington 26 Apr 2004.
CS 330 Programming Languages 09 / 18 / 2007 Instructor: Michael Eckmann.
ECI 2007: Specification and Verification of Object- Oriented Programs Lecture 1.
ESC Java. Static Analysis Spectrum Power Cost Type checking Data-flow analysis Model checking Program verification AutomatedManual ESC.
Well-cooked Spaghetti: Weakest-Precondition of Unstructured Programs Mike Barnett and Rustan Leino Microsoft Research Redmond, WA, USA.
Describing Syntax and Semantics
Floyd Hoare Logic. Semantics A programming language specification consists of a syntactic description and a semantic description. Syntactic description:symbols.
Pre/Post Condition Logic 03/06/2013. Agenda Hoare’s Logic Overview Application to Pre/Post Conditions.
1 Inference Rules and Proofs (Z); Program Specification and Verification Inference Rules and Proofs (Z); Program Specification and Verification.
Proofs of Correctness: An Introduction to Axiomatic Verification Prepared by Stephen M. Thebaut, Ph.D. University of Florida CEN 5035 Software Engineering.
1 Formal Semantics of Programming Languages “Program testing can be used to show the presence of bugs, but never to show their absence!” --Dijkstra.
Chapter 25 Formal Methods Formal methods Specify program using math Develop program using math Prove program matches specification using.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
CS 363 Comparative Programming Languages Semantics.
1 cs205: engineering software university of virginia fall 2006 Avoiding Software Disasters.
Reasoning about programs March CSE 403, Winter 2011, Brun.
Program Analysis and Verification Spring 2014 Program Analysis and Verification Lecture 4: Axiomatic Semantics I Roman Manevich Ben-Gurion University.
Chapter 3 Part II Describing Syntax and Semantics.
Semantics In Text: Chapter 3.
Languages and Compilers
COP4020 Programming Languages Introduction to Axiomatic Semantics Prof. Robert van Engelen.
Principle of Programming Lanugages 3: Compilation of statements Statements in C Assertion Hoare logic Department of Information Science and Engineering.
Cs7100(Prasad)L18-9WP1 Axiomatic Semantics Predicate Transformers.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
C HAPTER 3 Describing Syntax and Semantics. D YNAMIC S EMANTICS Describing syntax is relatively simple There is no single widely acceptable notation or.
Chapter 3 of Programming Languages by Ravi Sethi
Proving Loops Testing debugging and verification
CSE 331 Software Design & Implementation
Formal Methods in Software Engineering 1
CSE 331 Software Design and Implementation
Predicate Transforms II
Hoare-style program verification
Reasoning About Code; Hoare Logic
Lecture 5 Floyd-Hoare Style Verification
Programming Languages and Compilers (CS 421)
Programming Languages 2nd edition Tucker and Noonan
Semantics In Text: Chapter 3.
Formal Methods in software development
Predicate Transformers
Formal Methods in software development
Proofs of Correctness: An Introduction to Axiomatic Verification
Predicate Transforms II
Predicate Transforms I
Program correctness Axiomatic semantics
Program Verification with Hoare Logic
Programming Languages and Compilers (CS 421)
Programming Languages 2nd edition Tucker and Noonan
COP4020 Programming Languages
Presentation transcript:

Partial correctness © Marcelo d’Amorim 2010

Intuition Program and mathematical formula are similar. Both manipulate symbols and have precise syntax and semantics. © Marcelo d’Amorim 2010 Encode program state as a predicate and statements as predicate transformers.

For verification… Reason about programs as logical formulae © Marcelo d’Amorim 2010 Derive formula from program. If program is incorrect should find contradictions!

Basis: Floyd-Hoare Triples P and Q denote pre and post conditions on S © Marcelo d’Amorim 2010 {P} S {Q}

Semantic distinction Partial correctness: For all states that satisfy P, if S terminates, then Q must hold in that state Total correctness: For all states that satisfy P, then S terminates and the resulting state satisfies Q © Marcelo d’Amorim 2010 {P} S {Q}

Is this valid? © Marcelo d’Amorim 2010 {true} while (true) x:=2 {1==2}

Is this valid? Answer: Only under partial correctness since false (due to non termination) implies absurd © Marcelo d’Amorim 2010 {true} while (true) x:=2 {1==2}

Example © Marcelo d’Amorim 2010 {y<=3} x:=2*y+1 {x<=7 and y<=3}

Exercise Propose other preconditions P that makes this post condition to hold © Marcelo d’Amorim 2010 {P?} x:=2*y+1 {x<=7 and y<=3}

Definition: Weaker formula A formula A is weaker than B if B -> A. Given a set of formulas {A1,…,An}, Ai is the weakest in the set if Aj -> Ai for all j in [1,n]. © Marcelo d’Amorim 2010 Definition of stronger is symmetric.

Back to previous exercise Propose other preconditions P that makes this post condition to hold © Marcelo d’Amorim 2010 {P?} x:=2*y+1 {x<=7 and y<=3} We want to find the weakest predicate P (i.e., permissive/liberal/general) that is strong enough to make post condition hold.

Axiomatic semantics of programs Define semantics of each construct in terms of its effects on global state – Most popular definitions: wp and sp – Basis to automated derivation of pgm. obligations © Marcelo d’Amorim 2010

WP and SP wp (weakest precondition): Derive most general (weakest) accepting condition on state that results in correct executions sp (strongest postcondition): Derive most specific (strongest) condition that holds in every final states from correct executions © Marcelo d’Amorim 2010

Fragment of Pascal [ASSIGN] wp(x:=t, p(x)) = p(x) {x <- t} [COMP] wp(S1;S2, q) = wp(S1,wp(S2,q)) [COND] wp(if B then S1 else S2, q) = B-> wp(S1,q) and not B -> wp(S2,q) [WHILE] wp(while B do S, q) = (not B -> q) and B -> wp(S; while B do S, q) © Marcelo d’Amorim 2010 Oops… Cannot mechanically compute it!

Exercise: Compute the following wp(x:=x+1; y:=y+2, x < y) wp(x:=x+1; y:=y+2, x = (b - y)*a) wp(if y=0 then x:=0 else x:=y+1, x = y) © Marcelo d’Amorim 2010

Verification Conditions (VCs) © Marcelo d’Amorim 2010 S ; assert Q {?} S {Q} {P} S {Q} assume P ; S {P} S {True} {P => P0} S {True}

Verification Conditions (VCs) © Marcelo d’Amorim 2010 assume P; S ; assert Q {P} S {Q} {P => P0} S {Q}

VC generators One rule for each language statement Conceptually, one can derive a predicate for entire program with assistance of rules © Marcelo d’Amorim 2010 S 1 ; S 2 ; … ; S n P 1 P 2 P 3 P n-1 P n statements predicates

VC generators One rule for each language statement Conceptually, one can derive a predicate for entire program with assistance of rules © Marcelo d’Amorim 2010 S 1 ; S 2 ; … ; S n P 1 P 2 P 3 P n-1 P n statements predicates Interested reader should look George Necula’s work on proof-carrying code and also the Spec# and ESCJava tools.

Deductive System © Marcelo d’Amorim 2010 Mathematical Logic for Computer Science. Mordechai Ben-Ari, Springer

Exercise Generate weakest precondition for the program below to validate the assertion © Marcelo d’Amorim 2010 x := 0 y := b; while y <> 0 do begin x:= x + a; y:= y – 1 end; assert x = a * b

Conclusions Partial correctness is a cornerstone in program language and verification Very important to note. Not automatic! – Manual generation of loop invariants is costly – First-order logics alone is undecidable © Marcelo d’Amorim 2010