Formal Methods in software development

Slides:



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

Program verification: flowchart programs Book: chapter 7.
Program verification: flowchart programs Book: chapter 7.
Copyright , Doron Peled and Cesare Tinelli. These notes are based on a set of lecture notes originally developed by Doron Peled at the University.
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
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
Formal Semantics of Programming Languages 虞慧群 Topic 5: Axiomatic Semantics.
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.
Partial correctness © Marcelo d’Amorim 2010.
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.
1 Discrete Structures Lecture 29 Predicates and Programming Read Ch
Predicate Transformers
Program Proving Notes Ellen L. Walker.
1/22 Programs : Semantics and Verification Charngki PSWLAB Programs: Semantics and Verification Mordechai Ben-Ari Mathematical Logic for Computer.
CSE115/ENGR160 Discrete Mathematics 04/12/11 Ming-Hsuan Yang UC Merced 1.
Hoare-style program verification K. Rustan M. Leino Guest lecturer Rob DeLine’s CSE 503, Software Engineering University of Washington 26 Apr 2004.
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.
Software Verification Bertrand Meyer Chair of Software Engineering Lecture 2: Axiomatic semantics.
Describing Syntax and 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.
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.
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.
Program Analysis and Verification Spring 2014 Program Analysis and Verification Lecture 4: Axiomatic Semantics I Roman Manevich Ben-Gurion University.
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.
Program Analysis and Verification Spring 2015 Program Analysis and Verification Lecture 4: Axiomatic Semantics I Roman Manevich Ben-Gurion University.
Principle of Programming Lanugages 3: Compilation of statements Statements in C Assertion Hoare logic Department of Information Science and Engineering.
Dr. Naveed Riaz Design and Analysis of Algorithms 1 1 Formal Methods in Software Engineering Lecture # 26.
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
6/12/20161 a.a.2015/2016 Prof. Anna Labella Formal Methods in software development.
Hoare Logic LN chapter 5, 6 but without 6.8, 6.12, 6.13 (to be discussed later) Hoare Logic is used to reason about the correctness of programs. In the.
Formal Methods in software development
Proving Loops Testing debugging and verification
Formal Methods in Software Engineering 1
Hoare-style program verification
Mathematical Structures for Computer Science Chapter 1
Reasoning About Code; Hoare Logic
Lecture 5 Floyd-Hoare Style Verification
Lecture 2: Axiomatic semantics
Axiomatic semantics Points to discuss: The assignment statement
Programming Languages and Compilers (CS 421)
Programming Languages 2nd edition Tucker and Noonan
Formal Methods in software development
Formal Methods in software development
Section 1: Code Reasoning
Formal Methods in software development
Predicate Transformers
Proofs of Correctness: An Introduction to Axiomatic Verification
Formal Methods in software development
Program correctness Axiomatic semantics
Program Verification with Hoare Logic
Lecture 2: Axiomatic semantics
CIS 720 Lecture 3.
Programming Languages and Compilers (CS 421)
Formal Methods in software development
CIS 720 Lecture 3.
Programming Languages 2nd edition Tucker and Noonan
COP4020 Programming Languages
Presentation transcript:

Formal Methods in software development a.a.2016/2017 Prof. Anna Labella 2/28/2019

concurrent and sequential systems Hoare Logic Dealing with critical situations Software aging See Ben Ari, Huth Ryan chap.4 2/28/2019

Verifying satisfiability of properties A posteriori Model Checking Automatic Model-based Verifying satisfiability of properties A posteriori Application: concurrent and reactive systems Hoare Logic Semiautomatic Proof-based Verifying satisfiability of properties A priori Application: sequential and transformational programs 2/28/2019

Our language Our core language has three syntactic domains: integer expressions, boolean expressions and commands Arithmetical expressions E ::= n | x | (−E) | (E + E) | (E − E) | (E ∗ E) Propositions B ::= true | false | (!B) | (B &B) | (B ||B) | (E < E) Commands C ::= x = E | C;C | if B {C} else {C} | while B {C} 2/28/2019

Hoare triples Let us define |=part (|φ|) S (|ψ|) If s is a state verifying φ, then, by applying the instruction S, we obtain a state where ψ holds. φ is called “precondition” ψ “postcondition” 2/28/2019

Hoare triples: examples (|x> 0|) S (| y.y < x |) Many possible solutions: 2/28/2019

Partial and total correctness If preconditions are verified: A then, after the execution of the program B1 postconditions are verified: B2 A  (B1  B2) 2/28/2019

Partial correctness If preconditions are verified: A Then, if the program teminates B1 postconditions are verified: B2 A  (B1  B2) 2/28/2019

Total correctness If preconditions are verified: A then, the program terminates B1 and postconditions are verified: B2 A  (B1  B2) !?!?! 2/28/2019

Total correctness The only command that can be non terminating is the while command 2/28/2019

A deductive system tree-like proofs 2/28/2019

Hoare logic (proof rules for partial correctness) (|φ1|) C1 (|φ2|) (|φ2|) C2(|φ3|) composition (|φ1|) C1 ; C2 (|φ3|) ________________________ assignment (|ψ [E/x]|) x = E (|ψ|) (|φB|) C1 (|ψ|) (|φ¬ B|) C2 (|ψ|) if-statement (|φ|) if B then C1 else C2 (|ψ|) (|ψB|) C (|ψ|) partial while (|ψ|) while B do C (|ψ¬B|) (|φ’ φ|) (|φ|) C (|ψ|) (|ψ  ψ’|) implied (|φ’|) C (|ψ’|) 2/28/2019

Proofs as trees They are difficult to deal with 2/28/2019

Proof tableaux (|φ0|) C1 (|φ1|) C2 ……(|φn-1|) Cn (|φn|) How? Reduce a program to a concatenation of steps, inserting justification between any two of them (|φ0|) C1 (|φ1|) C2 ……(|φn-1|) Cn (|φn|) Going backword from the postcondition to the precondition How? 2/28/2019

Weaker condition φ  ψ means that φ is stronger than ψ (because “not as true as” ψ) We proceed backwards: Given (|φ|) C (|ψ|), we can compute the weakest precondition wp (C, ψ) (predicate trasformer) s.t. wp (C, ψ) C (|ψ|) Hence to prove a triple, we have to show: (|φ|) C (|ψ|)  φwp (C, ψ) 2/28/2019

Semantically We usually identify the set of states verifying a property with the property itself and work bottom up in the verification looking for the maximal set of states verifying the precondition in order to get the postcodition φ  ψ means that the set of states verifying |φ| is contained in the set of states verifying |ψ| |φ|  |ψ| 2/28/2019

(inductive definition) Weakest precondition (inductive definition) Hence we look for the maximal set of states s.t., starting from one of them, after doing C, we reach a state Satisfying the postcondition wp (x = E, ψ) = [E/x] ψ wp (C;C‘, ψ) = wp (C, wp (C‘, ψ )) wp (if B then C1 else C2, ψ ) = (B wp (C1, ψ ) (B  wp (C2, ψ)) wp (while B do C, ψ) = ( B  ψ )(B wp (C; while B do C, ψ)) 2/28/2019

Exercises 2/28/2019

Exercises (| u = x + y |) z = x; assignment z = z + y; assignment u=z; assignment (| u = x + y |) 2/28/2019

Exercises (| z = x + y |) (| u = x + y |) z = x; assignment z = z + y; assignment (| z = x + y |) u=z; assignment (| u = x + y |) 2/28/2019

Exercises (assignment) z = x; assignment (| z + y = x + y |) z = z + y; assignment (| z = x + y |) u=z; assignment (| u = x + y |) 2/28/2019

Exercises (assignment) (| x + y = x + y |) z = x; assignment (| z + y = x + y |) z = z + y; assignment (| z = x + y |) u=z; assignment (| u = x + y |) 2/28/2019

Exercises (assignment) (| x + y = x + y |) z = x; assignment (| z + y = x + y |) z = z + y; assignment (| z = x + y |) u=z; assignment (| u = x + y |) 2/28/2019

Exercises (assignment) 2/28/2019

Exercises (assignment) The first one is immediate (| x = x |) (| y = x |) (| x = x  x>1|) (| x = x  x>a|) (| y = x  y>a|) (|y > 0  x>y|) 2/28/2019

Exercises (assignment) 2/28/2019

Exercises (assignment) x := x+1 ; y := x+1 u := x+2 ; v := y+3 ; z := u+v 2/28/2019

Exercises (assignment) (| x+1 + 1 = x + 2 |) t = x + 1; (| t + 1 = x + 2 |) z = t + 1; (| z = x + 2 |) y = z; (| y = x + 2 |) 2/28/2019

Exercises (if then else) 2/28/2019

Exercises (if then else) (| x>y|) (|  x>y|) (| y = min (x, y) |) (| x = min (x, y) |) z = y; z = x; (| z = min (x, y) |) 2/28/2019

Exercises (if then else) 2/28/2019

Invariants (while do) 2/28/2019

Example (while do) 2/28/2019

Example cont’d 2/28/2019

Example cont’d 2/28/2019

Exercise (while do) Invariant? Total correctness? 2/28/2019

Hoare triples: total correctness Let us define |= tot(|φ|) S (|ψ|) If s is a state verifying φ, then, by applying the instruction S, then S terminates and we obtain a state where ψ holds. φ is called “precondition” ψ “postcondition” 2/28/2019

Hoare logic: total correctness If we want to prove total correctness, we need (|ψB  0≤E=E0|) C (|ψ0≤E<E0|) total while (|ψ0≤E|) while B do C (|ψ¬B|) Variants 2/28/2019

Hoare triples: total correctness Fac1 2/28/2019

Hoare logic: total correctness 2/28/2019