Programming Language Semantics Axiomatic Semantics Chapter 6.

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.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 12.
Semantics Static semantics Dynamic semantics attribute grammars
Copyright , Doron Peled and Cesare Tinelli. These notes are based on a set of lecture notes originally developed by Doron Peled at the University.
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 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
Formal Specification and Verification. Specifications Imprecise specifications can cause serious problems downstream Lots of interpretations even with.
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.
1/22 Programs : Semantics and Verification Charngki PSWLAB Programs: Semantics and Verification Mordechai Ben-Ari Mathematical Logic for Computer.
Program Analysis and Verification Spring 2014 Program Analysis and Verification Lecture 5: Axiomatic Semantics II Roman Manevich Ben-Gurion University.
CS 355 – Programming Languages
Programming Language Semantics Inductive Definitions Mooly SagivEran Yahav Schrirber 317Open space
Programming Language Semantics Denotational Semantics Chapter 5.
1 Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications.
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
Programming Language Semantics Denotational Semantics Chapter 5 Part II.
Axiomatic Semantics Dr. M Al-Mulhem ICS
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
PSUCS322 HM 1 Languages and Compiler Design II Formal Semantics Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU Spring.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Axiomatic Semantics ICS 535.
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
Software Verification Bertrand Meyer Chair of Software Engineering Lecture 2: Axiomatic semantics.
Programming Language Semantics Axiomatic Semantics of Parallel Programs.
Describing Syntax and Semantics
Program Analysis and Verification Spring 2015 Program Analysis and Verification Lecture 2: Operational Semantics I Roman Manevich Ben-Gurion University.
Formal Semantics of Programming Languages 虞慧群 Topic 3: Principles of Induction.
Propositional Logic Dr. Rogelio Dávila Pérez Profesor-Investigador División de Posgrado Universidad Autónoma Guadalajara
Reading and Writing Mathematical Proofs Spring 2015 Lecture 4: Beyond Basic Induction.
Program Analysis and Verification Spring 2014 Program Analysis and Verification Lecture 4: Axiomatic Semantics I Roman Manevich Ben-Gurion University.
CSE Winter 2008 Introduction to Program Verification January 31 proofs through simplification.
COP4020 Programming Languages Introduction to Axiomatic Semantics Prof. Robert van Engelen.
From Hoare Logic to Matching Logic Reachability Grigore Rosu and Andrei Stefanescu University of Illinois, USA.
1 Finite Model Theory Lecture 1: Overview and Background.
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.
Daniel Kroening and Ofer Strichman 1 Decision Procedures An Algorithmic Point of View Basic Concepts and Background.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
Program Analysis and Verification
Formal Semantics of Programming Languages 虞慧群 Topic 2: Operational Semantics.
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
CENG 424-Logic for CS Introduction Based on the Lecture Notes of Konstantin Korovin, Valentin Goranko, Russel and Norvig, and Michael Genesereth.
Spring 2017 Program Analysis and Verification
Spring 2016 Program Analysis and Verification
Program Analysis and Verification
Spring 2017 Program Analysis and Verification Operational Semantics
Mathematical Structures for Computer Science Chapter 1
Lecture 5 Floyd-Hoare Style Verification
Programming Languages 2nd edition Tucker and Noonan
Formal Methods in software development
Predicate Transformers
Formal Methods in software development
Program correctness Axiomatic semantics
Lecture 2: Axiomatic semantics
Spring 2016 Program Analysis and Verification Operational Semantics
CIS 720 Lecture 3.
CIS 720 Lecture 3.
Programming Languages 2nd edition Tucker and Noonan
COP4020 Programming Languages
Presentation transcript:

Programming Language Semantics Axiomatic Semantics Chapter 6

Motivation What do we need in order to prove that the program does what it supposed to do? Specify the required behavior Compare the behavior with the one obtained by the denotational/operational semantics Develop a proof system for showing that the program satisfies a requirement Mechanically use the proof system to show correctness The meaning of a program is a set of verification rules

Plan The basic idea An assertion language Semantics of assertions Proof rules An example Soundness Completeness

Example Program S:=0 N := 1 while  (N=101) do S := S + N ; N :=N+1 N=101 S=∑ 1  m  100 m

Example Program S:=0 {S=0} N := 1 {S=0  N=1} while  (N=101) do S := S + N ; N :=N+1 {N=101  S=∑ 1  m  100 m}

Example Program S:=0 {S=0} N := 1 {S=0  N=1} while  (N=101) do S := S + N ; N :=N+1 {N=101  S=∑ 1  m  100 m}

Example Program S:=0 {S=0} N := 1 {S=0  N=1} while {1  N  101  S=∑ 1  m  N-1 m}  (N=101) do S := S + N ; {1  N < 101  S=∑ 1  m  N m} N :=N+1 {N=101  S=∑ 1  m  100 m}

Partial Correctness {P}c{Q} –P and Q are assertions (extensions of Boolean expressions) –c is a command –For all states  which satisfies P, if the execution of c from state  terminates in state  ’, then  ’ satisfies Q {true}while true do skip{false}

Total Correctness [P]c[Q] –P and Q are assertions (extensions of Boolean expressions) –c is a command –For all states  which satisfies P, the execution of c from state  must terminates in a state  ’  ’ satisfies Q

Formalizing Partial Correctness   A –A is true in  {P} c {Q} – ,  ’  ∑. (   P &   ’ )   ’  Q –  ∑. (   P & C  c    )  C  c    Q Convention for all A  A ,  ’  ∑.   P  C  c    Q

The Assertion Language Extend Bexp Allow quantifications –  i: … –  i: …  i. k=i  l Import well known mathematical concepts –n!  n  (n-1)   2  1

The Assertion Language Aexpv a:= n | X | i | a 0 + a 1 | a 0 - a 1 | a 0  a 1 Assn A:= true | false | a 0 = a 1 | a 0  a 1 | A 0  A 1 | A 0  A 1 |  A | A 0  A 1 |  i. A |  i. A

Example while  (M=N) do if M  N then N := N – M else M := M - N

Free and Bound Variables An integer variable is bound when it occurs in the scope of a quantifier Otherwise it is free Examples  i. k=i  L (i+100  77)  i.j+1=i+3) FV(n) = FV(X) =  FV(i) = {i} FV(a 0 + a 1 )=FV(a 0 -a 1 )=FV(a 0  a 1 ) = FV(a 0 )  FV(a 1 ) FV(true)=FV(false)=  FV(a 0 = a 1 )=FV(a 0  a 1 )= FV(a 0 )  FV(a 1 ) FV(A 0  A 1 )=FV(A 0  A 1 ) =FV(A 0  A 1 )= FV(A 0 )  FV(A 1 ) FV(  A)=FV(A) FV(  i. A)=FV(  i. A)= FV(A)  {i}

Substitution Visualization of an assertion A ---i---i---- Consider a “pure” arithmetic expression A[a/i] ---a---a--- n[a/i] = n X[a/i]=X i[a/i] = a j[a/i] = j (a 0 + a 1 )[a/i] = a 0 [a/i] + a 1 /[a/i] (a 0 - a 1 )[a/i] = a 0 [a/i] – a 1 [a/i] (a 0  a 1 )[a/i]= a 0 [a/i]  a 1 [a/i]

Substitution Visualization of an assertion A ---i---i---- Consider a “pure” arithmetic expression A[a/i] ---a---a--- true[a/i] = true false[a/i]=false (a 0 = a 1 )[a/i] = (a 0 /[a/i] = a 1 [a/i]) (a 0  a 1 )[a/i] = (a 0 /[a/i]  a 1 [a/i]) (A 0  A 1 )[a/i] = (A 0 [a/i]  A 1 [a/i]) (A 0  A 1 )[a/i]= (A 0 [a/i]  A 1 [a/i]) (A 0  A 1 )[a/i] = (A 0 [a/i]  A 1 [a/i])[a/i] (  A)[a/i] =  (A[a/i]) (  i. A)[a/i] =  i. A (  j. A)[a/i] = (  i. A[a/i]) (  i. A)[a/i] =  i. A (  j. A)[a/i] =(  i. A[a/j])

Location Substitution Visualization of an assertion A ---X---X---- Consider a “pure” arithmetic expression A[a/X] ---a---a---

Example Assertions i is a prime number i is the least common multiple of j and k

Semantics of Assertions An interpretation I:intvar  N The meaning of Aexpv –Av  n  I  =n –Av  X  I  =  (X) –Av  i  I  = I(i) –Av  a0+a1  I  = Av  a0  I  +Av  a1  I  –… For all a  Aexp states  and Interpretations I –A  a   =Av  a  I 

Semantics of Assertions (II) I[n/i] change i in I to n For I and  , define   I A by structural induction –   I true –   I (a 0 = a 1 ) if Av  a 0  I  = Av  a 1  I  –   I (A  B) if   I A and   I B –   I  A if not   I A –   I A  B if (not   I A) or   I B) –   I  iA   I[n/i] A for all n  N –   A

Proposition 6.4 For all b  Bexp states  and Interpretations I B  b   = true iff   I b B  b   = false iff not   I b

Partial Correctness Assertions {P}c{Q} –P, Q  Assn and c  Com For a state    and interpretation I –   I {P}c{Q} if (   I P  C  c    I Q) Validity –When   ,   I {P}c{Q} we write  I {P}c{Q} –When   , and I   I {P}c{Q} we write  {P}c{Q} {P}c{Q} is valid

The extension of an assertion A I  {    |   I A }

The extension of assertions Suppose that  (P  Q) Then for any interpretation I   .   I P    I Q PIQIPIQI  QIQI PIPI

The extension of assertions Suppose that  {P}c{Q} Then for any interpretation I   .   I P  C  c    I Q C  c  P I  Q I  QIQI PIPI CcCc

Hoare Proof Rules for Partial Correctness {A} skip {A} {B[a/X]} X:=a {B} {P} c 0 {C} {C} c 1 {Q} {P} c 0 ;c 1 {Q} {P  b} c 0 {Q} {P  b} c 1 {Q} {P} if b then c 0 else c 1 {Q} {I  b} c {I} {I} while b do c{I  b}  P  P’ {P’} c {Q’}  Q’  Q {P} c {Q}

Example while X > 0 do Y := X  Y; X := X – 1

Soundness Every theorem obtained by the rule system is valid –  {P} c {Q}   {P} c {Q} The system can be implemented (HOL, LCF) –Requires user assistance Proof of soundness –Every rule preserves validity (Theorem 6.1)

Completeness Every valid theorem can be derived by the rule system is valid –  {P} c {Q}   {P} c {Q} But what about Gödel’s incompleteness? Relative completeness –Assume that every math theorem is valid Chapter 7 –Uses Weakest Preconditions

Summary Axiomatic semantics provides an abstract semantics Can be used to explain programming Can be automated More effort is required to make it practical