Predicate Transforms I

Slides:



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

Functional Verification III Prepared by Stephen M. Thebaut, Ph.D. University of Florida Software Testing and Verification Lecture Notes 23.
Axiomatic Verification I Prepared by Stephen M. Thebaut, Ph.D. University of Florida Software Testing and Verification Lecture 17.
Partial correctness © Marcelo d’Amorim 2010.
ISBN Chapter 3 Describing Syntax and Semantics.
Copyright © 2006 Addison-Wesley. All rights reserved. 3.5 Dynamic Semantics Meanings of expressions, statements, and program units Static semantics – type.
1 Discrete Structures Lecture 29 Predicates and Programming Read Ch
Predicate Transformers
Program Proving Notes Ellen L. Walker.
Duminda WijesekeraSWSE Program Correctness1 SWSE 623 Program Correctness -Pre-condition, Post-conditions and Loop invariants.
1/22 Programs : Semantics and Verification Charngki PSWLAB Programs: Semantics and Verification Mordechai Ben-Ari Mathematical Logic for Computer.
CS 355 – Programming Languages
Hoare-style program verification K. Rustan M. Leino Guest lecturer Rob DeLine’s CSE 503, Software Engineering University of Washington 26 Apr 2004.
Describing Syntax and Semantics
Floyd Hoare Logic. Semantics A programming language specification consists of a syntactic description and a semantic description. Syntactic description:symbols.
Exam 2 Help Session Prepared by Stephen M. Thebaut, Ph.D. University of Florida Software Testing 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.Determine the following weakest pre-conditions. a. wp(paint the living room ceiling, the house is all painted)
CS 363 Comparative Programming Languages Semantics.
Chapter 3 Part II Describing Syntax and Semantics.
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
Functional Verification I Prepared by Stephen M. Thebaut, Ph.D. University of Florida Software Testing and Verification Lecture Notes 21.
Axiomatic Verification II Prepared by Stephen M. Thebaut, Ph.D. University of Florida Software Testing and Verification Lecture Notes 18.
Functional Verification III
Weakest Precondition of Unstructured Programs
Spring 2017 Program Analysis and Verification
Rule of Sequential Composition
Reasoning About Code.
Proving Loops Testing debugging and verification
CSE 331 Software Design & Implementation
White-Box Testing Techniques II
Prepared by Stephen M. Thebaut, Ph.D. University of Florida
Functional Verification IV: Revisiting Loop Invariants
Predicate Transforms II
Hoare-style program verification
Functional Verification IV: Revisiting Loop Invariants
Functional Verification III
White-Box Testing Techniques III
Formal Program Specification
Predicate Transforms I
White-Box Testing Techniques II
Functional Verification I
Programming Languages and Compilers (CS 421)
Exercise Solutions: Functional Verification
Formal Program Specification
Prepared by Stephen M. Thebaut, Ph.D. University of Florida
Exercise Solutions: Functional Verification
Axiomatic Verification II
White-Box Testing Techniques III
Functional Verification I
Section 1: Code Reasoning
Axiomatic Verification II
Axiomatic Verification I
Predicate Transformers
Proofs of Correctness: An Introduction to Axiomatic Verification
Functional Verification II
Functional Verification IV: Revisiting Loop Invariants
Axiomatic Verification I
Predicate Transforms I
Prepared by Stephen M. Thebaut, Ph.D. University of Florida
Functional Verification III
Predicate Transforms II
Functional Verification III
Functional Verification IV: Revisiting Loop Invariants
Prepared by Stephen M. Thebaut, Ph.D. University of Florida
Model-based vs. Functional Program Specification and Correctness
Formal Program Specification
COP4020 Programming Languages
Presentation transcript:

Predicate Transforms I Software Testing and Verification Lecture 19 Prepared by Stephen M. Thebaut, Ph.D. University of Florida

Predicate Transforms I and II Introduction Proving strong correctness Assignment statements Sequencing Selection statements --------------------------- Iteration

Introduction What are Predicate Transforms? An extension of axiomatic verification. Rules are provided for transforming post-conditions into weakest pre-conditions with respect to various program constructs.

Introduction (cont’d) What is a weakest pre-condition? It is the necessary pre-condition for program S to terminate in state Q. It is denoted wp(S,Q) and read, “the weakest pre-condition of S with respect to Q.”

Proving Strong Correctness To prove {P} S {Q} and to prove that P implies that S will terminate, show that P  wp(S,Q) We now consider rules for computing weakest pre-conditions for structured programs comprised of assignment statements, if-then (-else) statements, and while loops.

Rule for Assignment Statements wp(x:=E, Q(x,y,z))  Q(E,y,z)

Rule for Assignment Statements wp(x:=E, Q(x,y,z))  Q(E,y,z) Examples: wp(x:=y+3, x>0) =

Rule for Assignment Statements wp(x:=E, Q(x,y,z))  Q(E,y,z) Examples: wp(x:=y+3, x>0) = wp(x:=x+1, xn+1) =

Rule for Assignment Statements wp(x:=E, Q(x,y,z))  Q(E,y,z) Examples: wp(x:=y+3, x>0) wp(x:=x+1, xn+1) wp(x:=7, x=7) =

Rule for Assignment Statements wp(x:=E, Q(x,y,z))  Q(E,y,z) Examples: (cont’d) wp(x:=7, x=6) =

Rule for Assignment Statements wp(x:=E, Q(x,y,z))  Q(E,y,z) Examples: (cont’d) wp(x:=7, x=6) = wp(x:=7, y=7) =

Rule for Assignment Statements wp(x:=E, Q(x,y,z))  Q(E,y,z) Examples: (cont’d) wp(x:=7, x=6) = wp(x:=7, y=7) = wp(y:=-x, y=|x|) =

wp(S1, wp(S2,...wp(Sn-1, wp(Sn, Q))…)) Rule for Sequencing Rule: wp(S1;S2;...;Sn-1;Sn, Q)  wp(S1, wp(S2,...wp(Sn-1, wp(Sn, Q))…))

Rule for Sequencing (cont’d) Example: wp(C:=D+1; B:=C2; A:=B2, A=36)

Rule for Sequencing (cont’d) Example: wp(C:=D+1; B:=C2; A:=B2, A=36) C:=D+1 B:=C2 A:=B2 { A=36 }

Rule for Sequencing (cont’d) Example: wp(C:=D+1; B:=C2; A:=B2, A=36) C:=D+1 B:=C2 A:=B2 { A=36 } C:=D+1 B:=C2 A:=B2 { A=36 }

Rule for if-then-else Statement wp(if b then S1 else S2, Q)  (b Л wp(S1, Q)) V (¬b Л wp(S2, Q))

Rule for if-then-else Statement wp(if b then S1 else S2, Q)  (b Л wp(S1, Q)) V (¬b Л wp(S2, Q)) T F b S1 S2 {Q}

Rule for if-then-else Statement wp(if b then S1 else S2, Q)  (b Л wp(S1, Q)) V (¬b Л wp(S2, Q)) T F b b Л wp(S1, Q)) S1 S2 {Q}

Rule for if-then-else Statement wp(if b then S1 else S2, Q)  (b Л wp(S1, Q)) V (¬b Л wp(S2, Q)) T F b b Л wp(S1, Q)) ¬b Л wp(S2, Q)) S1 S2 {Q}

Rule for if-then-else Statement (cont’d) Example: wp(if x<0 then y:=-x else y:=x, y=|x|)

Rule for if-then Statement wp(if b then S, Q)  (b Л wp(S, Q)) V (¬b Л Q)

Rule for if-then Statement wp(if b then S, Q)  (b Л wp(S, Q)) V (¬b Л Q) T b F S {Q}

Rule for if-then Statement wp(if b then S, Q)  (b Л wp(S, Q)) V (¬b Л Q) T b b Л wp(S, Q)) F S {Q}

Rule for if-then Statement wp(if b then S, Q)  (b Л wp(S, Q)) V (¬b Л Q) T b b Л wp(S, Q)) F S ¬b Л Q {Q}

Rule for if-then Statement (cont’d) Example: wp(if x<0 then y:=-x, y=|x|)

{Z=B} if A>B then Z := A {Z=Max(A,B)} Exercise Prove the assertion below using the predicate transform based approach. {Z=B} if A>B then Z := A {Z=Max(A,B)}

{Z=B} if A>B then Z := A {Z=Max(A,B)} Exercise Prove the assertion below using the predicate transform based approach. {Z=B} if A>B then Z := A {Z=Max(A,B)} P S Q

{Z=B} if A>B then Z := A {Z=Max(A,B)} Exercise Prove the assertion below using the predicate transform based approach. {Z=B} if A>B then Z := A {Z=Max(A,B)} Hint: Compute the wp(S,Q) Show that P  wp(S,Q) P S Q

Predicate Transforms I Software Testing and Verification Lecture 19 Prepared by Stephen M. Thebaut, Ph.D. University of Florida