CIS 720 Lecture 3.

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.
In this episode of The Verification Corner, Rustan Leino talks about Loop Invariants. He gives a brief summary of the theoretical foundations and shows.
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.
Axiomatic Verification I Prepared by Stephen M. Thebaut, Ph.D. University of Florida Software Testing and Verification Lecture 17.
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.
Copyright © 2006 Addison-Wesley. All rights reserved. 3.5 Dynamic Semantics Meanings of expressions, statements, and program units Static semantics – type.
Predicate Transformers
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.
Axiomatic Semantics Dr. M Al-Mulhem ICS
Discrete Structures Chapter 2 Part B Mathematical Induction
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
Proofs, Recursion, and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProofs,
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.
Proving Program Correctness The Axiomatic Approach.
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
Proofs of Correctness: An Introduction to Axiomatic Verification Prepared by Stephen M. Thebaut, Ph.D. University of Florida CEN 5035 Software Engineering.
Chapter 5: Sequences, Mathematical Induction, and Recursion 5.5 Application: Correctness of Algorithms 1 [P]rogramming reliability – must be an activity.
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.
CIS 720 Correctness of Concurrent Programs. i := 1 max := A[1] do i < n  i = i + 1 if (max < A[i]) max = A[i] od.
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.
1 Section 8.2 Program Correctness (for imperative programs) A theory of program correctness needs wffs, axioms, and inference rules. Wffs (called Hoare.
1 Computer Algorithms Tutorial 2 Mathematical Induction Some of these slides are courtesy of D. Plaisted et al, UNC and M. Nicolescu, UNR.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
if ( condition ) statement; if is a Java reserved word The condition must be a boolean expression. It must evaluate to either true or false.
11/22/2016IT 3271 A formal system:Axioms and Rules, for inferring valid specification x := m; y := n; while ¬(x=y) do if x>y then x := x-y else y := y-x.
Chapter 3 of Programming Languages by Ravi Sethi
What I Teach (Do what I say, not what I do)
Formal Methods in Software Engineering 1
Mathematical Structures for Computer Science Chapter 1
Axiomatic semantics Points to discuss: The assignment statement
Programming Languages and Compilers (CS 421)
Programming Languages 2nd edition Tucker and Noonan
Denotational Semantics (Denotational Semantics)
Logic for Computer Security Protocols
Semantics In Text: Chapter 3.
Axiomatic Verification I
Predicate Transformers
Formal Methods in software development
Axiomatic Semantics Will consider axiomatic semantics (A.S.) of IMP:
Axiomatic Verification I
CIS 720 Lecture 5.
Program correctness Axiomatic semantics
Program Verification with Hoare Logic
CIS 720 Lecture 4.
CIS 720 Lecture 4.
CIS 720 Lecture 3.
Programming Languages and Compilers (CS 421)
CIS 720 Lecture 4.
CIS 720 Lecture 4.
Programming Languages 2nd edition Tucker and Noonan
COP4020 Programming Languages
CIS 720 Lecture 4.
Program Correctness an introduction.
Presentation transcript:

CIS 720 Lecture 3

Correctness of sequential programs Program logic { P } S { Q } If S begins in a state satisfying P and S terminates, then the resulting state satisfies Q. Partial correctness P = precondition Q = postcondition

Axioms Skip statement Assignment statement { P } skip { P } { Pxe } x := e { P } Pxe = P with all occurrences of x replaced by e { true } x := 5 { x = 5} { y = 1 } x := 5 { x = 5 /\ y = 1} { y = 1 } x := 5 { x + y = 6 }

Rule of consequence P’ => P, {P } S {Q}, Q => Q’ {P’ } S {Q’}

Alternative statement if B1  S1 [] …... [] Bn  Sn fi Bi = boolean guard Its evaluation does not change the state All guards are evaluated One of the true guards is selected non-deterministically and its statement executed. If no guards evaluates to true then skip

If-statement axiom 1 ≤ i ≤ N, { P /\ Bi } Si { Q } /\ ( P /\ !(B1\/....\/Bn)) => Q {P} if B1  S1 [] …... [] Bn  Sn fi {Q} {P} if B1  S1 [] B2  S2 : Bn  Sn fi {P /\ B1} {P} {Q}

{true} m >=

Rule of Consequence

Iterative rule do B1  S1 [] …... [] Bn  Sn od Perform all of the following steps until all guards evaluate to false Evaluate all guards Select one of the true guards non-deterministically and execute the statement

Iterative statement axiom Loop invariant I is a predicate that holds before and after each iteration of the loop. 1 ≤ i ≤ N, { I /\ Bi } Si { I } {I} do B1  S1 [] …... [] Bn  Sn od {I /\ ¬(B1 \/....\/ Bn)}

Proof Outline Proof outline consists of one assertion before and after each statement (or one assertion for each control point). Assertion is supposed to indicate what must be true at that point Each assertion must follow from the previous assertion using either an axiom or logical implication

Example i := 1 fact := 1 do i < n  i = i + 1 fact =fact * i od {A1} i := 1 {A2} – using AA {A2} fact := 1 {A3} – using AA {A1: n > 0} A3  I i := 1 fact := 1 do i < n  i = i + 1 fact =fact * i od {A4 /\ i < n} i := i+1 {A5} – using AA {A2: n > 0 /\ i = 1} {A5} fact := fact *i {I} – using AA {I} do … od {I /\ I >= n} – using Do-loop axiom {A3: n > 0 /\ i = 1 /\ fact = 1} {I: n > 0 /\ fact = i! /\ i <= n} {A4: I /\ i < n} {A5: n > 0 /\ fact = (i – 1)! /\ i <= n} {I} {A6: I /\ i >= n} {fact = n!}

i { A4 /\ i < n }

i := 1 max := A[1] do i < n  i = i + 1 if (max < A[i]) max = A[i] od

Concurrency rule { Pi } Si { Qi } are interference free { P1 /\ …. /\ Pn } co S1 // …. // Sn { Q1 /\ …. /\ Qn}

Interference freedom Let a be a statement and C be an assertion. NI(a, C) iff { pre(a) /\ C } a { C } Execution of a does not invalidates (or interferes with C).

{ Pi } Si { Qi }, for all I, are interference free if for all assertions C in proof outline of Si, for all actions a in Sj, i != j NI(a, C) holds