This Week Finish relational semantics Hoare logic Interlude on one-point rule Building formulas from programs.

Slides:



Advertisements
Similar presentations
Technologies for finding errors in object-oriented software K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 Summer school on Formal Models.
Advertisements

Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Program Verification Using Hoares Logic Book: Chapter 7.
Synthesis, Analysis, and Verification Lecture 04c Lectures: Viktor Kuncak VC Generation for Programs with Data Structures “Beyond Integers”
Copyright , Doron Peled and Cesare Tinelli. These notes are based on a set of lecture notes originally developed by Doron Peled at the University.
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
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
1 Discrete Structures Lecture 29 Predicates and Programming Read Ch
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.
CS 355 – Programming Languages
CSE115/ENGR160 Discrete Mathematics 04/12/11 Ming-Hsuan Yang UC Merced 1.
Recursive Definitions Rosen, 3.4. Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 23 Instructor: Paul Beame.
4/17/2017 Section 3.6 Program Correctness ch3.6.
Software Verification Bertrand Meyer Chair of Software Engineering Lecture 2: Axiomatic semantics.
Describing Syntax and Semantics
Chapter 10 Sequences, Induction, and Probability Copyright © 2014, 2010, 2007 Pearson Education, Inc Mathematical Induction.
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.
RMIT University; Taylor's College1 Lecture 6  To apply the Principle of Mathematical Induction  To solve the Towers of Hanoi puzzle  To define a recurrence.
CSE 755, part3 Axiomatic Semantics Will consider axiomatic semantics (A.S.) of IMP: ::=skip | | | | ; | | Only integer vars; no procedures/fns; vars declared.
Reading and Writing Mathematical Proofs
Verifiable Programming Reason about imperative sequential programs such as Java programs Imperative program –defines state space defined by collection.
Program Analysis and Verification Spring 2015 Program Analysis and Verification Lecture 2: Operational Semantics I Roman Manevich Ben-Gurion University.
Chapter 3 (Part 3): Mathematical Reasoning, Induction & Recursion  Recursive Algorithms (3.5)  Program Correctness (3.6)
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.
Synthesis, Analysis, and Verification Lecture 05a Lectures: Viktor Kuncak Programs with Data Structures: Assertions for Accesses. Dynamic Allocation.
9.4 Mathematical Induction
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.
Principle of Programming Lanugages 3: Compilation of statements Statements in C Assertion Hoare logic Department of Information Science and Engineering.
This Week Lecture on relational semantics Exercises on logic and relations Labs on using Isabelle to do proofs.
Dr. Naveed Riaz Design and Analysis of Algorithms 1 1 Formal Methods in Software Engineering Lecture # 26.
Type soundness In a more formal way. Proving Soundness of Type Systems Goal of a sound type system: –if the program type checks, then it never “crashes”
1 Section 8.2 Program Correctness (for imperative programs) A theory of program correctness needs wffs, axioms, and inference rules. Wffs (called Hoare.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
Application: Algorithms Lecture 19 Section 3.8 Tue, Feb 20, 2007.
Program Analysis and Verification
Learning Javascript From Mr Saem
Verifiable Programming Reason about imperative sequential programs such as Java Imperative program –defines state space defined by collection of typed.
Reasoning About Code.
CSE 311: Foundations of Computing
Formal Methods in Software Engineering 1
Chapter 5 Induction and Recursion
Mathematical Structures for Computer Science Chapter 1
Lecture 5 Floyd-Hoare Style Verification
Axiomatic semantics Points to discuss: The assignment statement
Programming Languages and Compilers (CS 421)
Notes 9.5 – Mathematical Induction
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
Logic for Computer Security Protocols
Introduction to Programming Using Python PART 2
Formal Methods in software development
Predicate Transformers
Formal Methods in software development
Axiomatic Semantics Will consider axiomatic semantics (A.S.) of IMP:
Application: Algorithms
Application: Algorithms
Program correctness Axiomatic semantics
Program Verification with Hoare Logic
Lecture 2: Axiomatic semantics
Programming Languages and Compilers (CS 421)
COP4020 Programming Languages
Program Analysis and Verification
Program Correctness an introduction.
Presentation transcript:

This Week Finish relational semantics Hoare logic Interlude on one-point rule Building formulas from programs

Synthesis, Analysis, and Verification Lecture 03a Lectures: Viktor Kuncak Relational Semantics and Consequences Hoare Logic

Mapping Programs while (x > 1) { if (x % 2 = 0) x = x / 2 else x = 3 * x + 1 } into relations {((x 1,..., x n ), (x’ 1,..., x’ n )) | F(x 1,..., x n x’ 1,..., x’ n )}

Guarded Command Language assume(F) - stop execution if F does not hold pretend execution never happened s1 [] s2 - non-deterministic execution of both s1 and s2 s* - execute s zero, once, or more times

Guarded Commands and Relations - Idea x = T{(x,T) | true } gets more complex for more variables assume(F)Δ S S is set of values for which F is true (satisfying assignments of F) s*r* s 1 [] s 2 r 1 U r 2

Assignment for More Variables var x,y … y = x + 1

State as a Map from Variables to Values

‘if’ condition using assume and [] if (F) s1 else s2 (assume(F); s1) [] (assume(  F); s2)

‘while’ using assume and * while (F) c (assume(F); c)*; assume(  F)

Compute Relation for this Program r = 0; while (x > 0) { r = r + 3; x = x - 1 } As the program state use the pair of integer variables (r,x) 1) compute guarded command language for this program (express ‘while’ and ‘if’ using ‘assume’).

Compute Relation for this Program r = 0; while (x > 0) { r = r + 3; x = x - 1 } r = 0; ( assume(x>0); r = r + 3; x = x – 1 )* ; assume(x <= 0) assume(x>0); r = r + 3; x = x – 1 B*B* r = 0; B*; assume(x <= 0) 2) compute meaning of program pieces, from smaller to bigger

B r’ = r + 3 && x’ = x – k && x > 0

BkBk r’ = r + 3k && x’ = x – k && x > 0 && x – 1 > 0 &&... && x – (k-1) > 0 i.e. r’ = r + 3k && x’ = x – k && x – (k – 1) > 0i.e. x – k >= 0

B* (s,s’) in B*  exists k. (s,s’) in B k B* : exists k. k >= 0 && r’ = r + 3k && x’ = x – k && x – k >= 0 i.e. by one-point rule: r’ = r + 3(x-x’) && x’ >= 0 && x – x’ >= 0 and we must also add the diagonal

Havoc Statement Havoc statement is another useful declarative statement. It changes a given variable entirely arbitrarily: there will be one possible state for each possible value of integer variable. Expressing Assignment with Havoc+Assume We can prove that the following equality holds under certain conditions: x = E is havoc(x); assume(x==E) In other words, assigning a variable is the same as changing it arbitrarily and then assuming that it has the right value. Under what condition does this equality hold?

Correctness as Relation Inclusion program  relation p specification  relation s program meets specification: p s example: p = {((r,x),(r’,x’)). r’=2x && x’=0 } s = {((r,x),(r’,x’)). x > 0  r’ > x’ } then the above program p meets the specification s because implication holds: r’=2x && x’=0  ( x > 0  r’ > x’ )

Normal form for Loop-Free Programs Lemma: Let P be a program without loops. Then for some natural number n, where each p i is relation composition of – relations for assignments – diagonal relations Prove this.

Proof

Inductive Case

A Hoare Logic Proof //{0 <= y} i = y; //{0 <= y & i = y} r = 0; //{0 <= y & i = y & r = 0} while //{r = (y-i)*x & 0 <= i} (i > 0) ( //{r = (y-i)*x & 0 < i} r = r + x; //{r = (y-i+1)*x & 0 < i} i = i - 1 //{r = (y-i)*x & 0 <= i} ) //{r = x * y}

Hoare Logic see wiki