Proofs of Correctness: An Introduction to Axiomatic Verification Prepared by Stephen M. Thebaut, Ph.D. University of Florida CEN 5035 Software Engineering.

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.
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
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.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
Predicate Transformers
Program Proving Notes Ellen L. Walker.
1 Semantic Description of Programming languages. 2 Static versus Dynamic Semantics n Static Semantics represents legal forms of programs that cannot be.
CSE115/ENGR160 Discrete Mathematics 04/12/11 Ming-Hsuan Yang UC Merced 1.
Axiomatic Semantics Dr. M Al-Mulhem ICS
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Axiomatic Semantics ICS 535.
4/17/2017 Section 3.6 Program Correctness ch3.6.
Describing Syntax and Semantics
Proving Program Correctness The Axiomatic Approach.
Exam 2 Help Session Prepared by Stephen M. Thebaut, Ph.D. University of Florida Software Testing and Verification.
1 Inference Rules and Proofs (Z); Program Specification and Verification Inference Rules and Proofs (Z); Program Specification and Verification.
CSI 3125, Axiomatic Semantics, page 1 Axiomatic semantics The assignment statement Statement composition The "if-then-else" statement The "while" statement.
1 Formal Semantics of Programming Languages “Program testing can be used to show the presence of bugs, but never to show their absence!” --Dijkstra.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
CS 363 Comparative Programming Languages Semantics.
Semantics In Text: Chapter 3.
COP4020 Programming Languages Introduction to Axiomatic Semantics Prof. Robert van Engelen.
13 Aug 2013 Program Verification. Proofs about Programs Why make you study logic? Why make you do proofs? Because we want to prove properties of programs.
Static Techniques for V&V. Hierarchy of V&V techniques Static Analysis V&V Dynamic Techniques Model Checking Simulation Symbolic Execution Testing Informal.
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
Formal Methods in Software Engineering 1
Prepared by Stephen M. Thebaut, Ph.D. University of Florida
Functional Verification IV: Revisiting Loop Invariants
Predicate Transforms II
Functional Verification IV: Revisiting Loop Invariants
Functional Verification III
Predicate Transforms I
Lecture 5 Floyd-Hoare Style Verification
Functional Verification I
Axiomatic semantics Points to discuss: The assignment statement
Programming Languages and Compilers (CS 421)
Exercise Solutions: Functional Verification
Programming Languages 2nd edition Tucker and Noonan
Exercise Solutions: Functional Verification
Axiomatic Verification II
Semantics In Text: Chapter 3.
Functional Verification I
Axiomatic Verification II
Axiomatic Verification I
Formal Methods in software development
Predicate Transformers
Formal Methods in software development
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
Predicate Transforms I
Prepared by Stephen M. Thebaut, Ph.D. University of Florida
Programming Languages and Compilers (CS 421)
Programming Languages 2nd edition Tucker and Noonan
COP4020 Programming Languages
Program Correctness an introduction.
Presentation transcript:

Proofs of Correctness: An Introduction to Axiomatic Verification Prepared by Stephen M. Thebaut, Ph.D. University of Florida CEN 5035 Software Engineering

Important info for students: “Intro to Proofs of Correctness” is an elementary introduction to the verification material covered in CEN 4072/6070, Software Testing & Verification. Therefore, if you have already taken CEN 4072/6070, you will NOT be tested on this material in Exam 2. Instead, you will be tested on Sommerville Chaps 16 and 25 (“Software reuse” and “Configuration management”), which will NOT be covered in class.

Outline Introduction Weak correctness predicate Assignment statements Sequencing Selection statements Iteration

Introduction What is Axiomatic Verification? A formal method of reasoning about the functional correctness of a structured, sequential program by tracing its state changes from an initial (i.e., pre-) condition to a final (i.e., post-) condition according to a set of self-evident rules (i.e., axioms).

Introduction (cont’d) What is its primary goal? To provide a means for “proving” (or “disproving”) the functional correctness of a sequential program with respect to its (formal) specification.

Introduction (cont’d) What are the benefits of studying axiomatic verification? –Understanding its limitations. –Deeper insights into programming and program structures. –Criteria for judging both programs and programming languages. –The ability to formally verify small (or parts of large) sequential programs.

Introduction (cont’d) Bottom line: even if you never attempt to “prove” a program correct outside this course, the study of formal verification should change the way you write and read programs.

Weak Correctness Predicate To prove that program S is (weakly) correct with respect to pre-condition P and post-condition Q, it is sufficient to show: {P} S {Q}. Interpretation of {P} S {Q}: “if the input (initial state) satisfies pre- condition P and (if) program S executes and terminates, then the output (final state) must satisfy post-condition Q.”

Weak Correctness Predicate (cont’d) Note that {P} S {Q} is really just a “double conditional” of the form: (A Л B)  C where A is “P holds before executing S”, B is “S terminates”, and C is “Q holds after executing S”. Therefore, what is the one and only case (in terms of the values of A, B, and C) for which {P} S {Q} is false?

Weak Correctness Predicate (cont’d) Thus, {P} S {Q} is true unless Q could be false if S terminates, given that P held before S executes. What are the truth values of the following assertions? (1) {x=1} y  x+1 {y>0}

Weak Correctness Predicate (cont’d) Thus, {P} S {Q} is true unless Q could be false if S terminates, given that P held before S executes. What are the truth values of the following assertions? (2) {x>0} x  x-1 {x>0}

Weak Correctness Predicate (cont’d) Thus, {P} S {Q} is true unless Q could be false if S terminates, given that P held before S executes. What are the truth values of the following assertions? (3) {1=2} k  5 {k<0}

Weak Correctness Predicate (cont’d) Thus, {P} S {Q} is true unless Q could be false if S terminates, given that P held before S executes. What are the truth values of the following assertions? (4) {true} while x <> 5 do x  x-1 {x=5} (Hint: When will S terminate?)

Weak Correctness Predicate (cont’d) We now consider techniques for proving that such assertions hold for structured programs comprised of assignment statements, if-then (-else) statements, and while loops. (Why these particular constructs?)

Reasoning about Assignment Statements For each of the following pre-conditions, P, and assignment statements, S, identify a “strong” post-condition, Q, such that {P} S {Q} would hold. A “strong” post-condition captures all after- execution state information of interest. We won’t bother with propositions such as X=X’ (“the final value of X is the same as the initial value of X”) for the time being.

Reasoning about Assignment Statements (cont’d) {P}S{Q} {J=6} K  3 {J=6} J  J+2 {A<B} Min  A {X<0} Y  -X

Reasoning about Assignment Statements (cont’d) For each of the following post-conditions, Q, and assignment statements, S, identify a “weak” pre-condition, P, such that {P} S {Q} would hold. (A “weak” pre-condition reflects only what needs to be true before.)

Reasoning about Assignment Statements (cont’d) {P}S{Q} I  4 {J=7 Л I =4} I  4 { I =4} I  4 { I =17} Y  X+3 {Y=10}

Reasoning about Sequencing In general: if you know {P} S 1 {R} and you know {R} S 2 {Q} then you know {P} S 1 ; S 2 {Q}. (So, to prove {P} S 1 ; S 2 {Q}, find {R}.)

Example 1 Prove the assertion: {A=5} B  A+2; C  B-A; D  A-C {A=5 Л D=3}

Reasoning about If_then_else Statements Consider the assertion: {P} if b then S 1 else S 2 {Q} What are the necessary conditions for this assertion to hold?

Necessary Conditions: If_then_else b S1S1 S2S2 {P} {Q} T F

Reasoning about If_then Statements Consider the assertion: {P} if b then S {Q} What are the necessary conditions for this assertion to hold?

Necessary Conditions: If_then b S {P} {Q} T F

Example 2 Prove the assertion: {Z=B} if A>B then Z  A {Z=Max(A,B)}

Proof Rules Before proceeding to while loops, let’s capture our previous reasoning about sequencing and selection statements in appropriate rules of inference (ROI). ROI for Sequencing: {P} S 1 {R}, {R} S 2 {Q} {P} S 1 ; S 2 {Q}

Proof Rules (cont’d) ROI for if_then_else statement: {P Л b } S 1 {Q}, {P Л  b} S 2 {Q} {P} if b then S 1 else S 2 {Q} ROI for if_then statement: {P Л b } S {Q}, (P Л  b)  Q {P} if b then S {Q}

Reasoning about Iteration Consider the assertion: {P} while b do S {Q} What are the necessary conditions for this assertion to hold?

Consider a Loop “ I nvariant” - I b S {P} T F {Q} I Л bI Л b I I I Л bI Л b and implies Q when and if the loop finally terminates… Suppose I holds initially… is preserved by S… then the assertion would hold!

Sufficient Conditions: while_do Thus, a ROI for the while_do statement is: P  I, { I Л b} S { I }, ( I Л  b)  Q {P} while b do S {Q} where the three antecedents are sometimes given the names initialization, preservation, and finalization, respectively.

Example 3 {true} Z  X J  1 while J<>Y do Z  Z+X J  J+1 end_while {Z=XY} Initialization: P  I Preservation: { I Л b} S { I } Finalization: ( I Л  b)  Q Use the invariant I : Z=XJ to prove:

Example 3 {true} Z  X J  1 while J<>Y do Z  Z+X J  J+1 end_while {Z=XY} Initialization: P  I What is “P”? (Z=X Л J=1) Does (Z=X Л J=1)  Z=XJ ? Yep! Use the invariant I : Z=XJ to prove: P

Example 3 {true} Z  X J  1 while J<>Y do Z  Z+X J  J+1 end_while {Z=XY} Initialization: P  I  Preservation: { I Л b} S { I } {Z=XJ Л J  Y} Z  Z+X {Z=X(J+1) Л J  Y} J  J+1 {Z=X((J-1)+1) Л J-1  Y}  Z=XJ Use the invariant I : Z=XJ to prove: b S

Example 3 {true} Z  X J  1 while J<>Y do Z  Z+X J  J+1 end_while {Z=XY} Initialization: P  I  Preservation: { I Л b} S { I }  Finalization: ( I Л  b)  Q Does (Z=XJ Л J=Y)  Z=XY ? Yep! Use the invariant I : Z=XJ to prove:

Example 3 {true} Z  X J  1 while J<>Y do Z  Z+X J  J+1 end_while {Z=XY} Initialization: P  I  Preservation: { I Л b} S { I }  Finalization: ( I Л  b)  Q  Use the invariant I : Z=XJ to prove:

Exercise See WHILE LOOP VERIFICATION EXERCISE on course website

Some Limitations of Formal Verification Difficulties can arise when dealing with: –parameters –pointers –synthesis of invariants –decidability of verification conditions –concurrency

Some Limitations of Formal Verification (cont’d) In addition, a formal specification: –may be expensive to produce –may be incorrect and/or incomplete –normally reflects functional requirements only Will the proof process be manual or automatic? Who will prove the proof?

That’s all, folks, but If you like formal verification… Take CEN 6070, Software Testing & Verification and learn about: –deriving invariants using the Invariant Status Theorem, –proving termination using the Method of Well-Founded Sets, –Predicate transforms (“weakest pre- conditions”) –function-theoretic verification (prove the correctness of loops without invariants!) –and MUCH more!

Proofs of Correctness: An Introduction to Axiomatic Verification Prepared by Stephen M. Thebaut, Ph.D. University of Florida CEN 5035 Software Engineering