Verification Frameworks and Hoare Logic

Size: px
Start display at page:

Download "Verification Frameworks and Hoare Logic"

Transcription

1 CMSC 630 February 11, Verification Frameworks and Hoare Logic Sources K. Apt and E.-R. Olderog. Verification of Sequential and Concurrent Programs (Second Edition). Springer-Verlag, Berlin, D. Gries. The Science of Programming. Springer-Verlag, Berlin, 1981.

2 CMSC 630 February 11, Verification Frameworks This course is about verifying systems mathematically. In order to do this, one needs a verification framework, which consists of following components. Class Sys of system descriptions. Sys must be given mathematically, with (at least) semantics and (usually) syntax. Class Spec of system specifications/requirements. Spec must also be given mathematically. Relation sat Sys Spec. Once a verification framework has been defined, verifying a specific systems S Sys against a specific requirementr Spec means proving thats sat R.

3 CMSC 630 February 11, Verification Frameworks (cont.) Given a verification framework, how does one establish whether or nots sat R? Two main approaches. Proof-based: Develop proof rules for proving S sat R and use them to prove correctness Algorithmic: Give decision procedures for computing if S sat R holds. In this class we will study several different verification frameworks, including ones that are proof-based and others that are algorithmic.

4 CMSC 630 February 11, Hoare Logic and Program Verification The first verification framework we will study: Hoare Logic. Sys consists of programs written in a simple guarded commands programming notation. Spec consists of pairs of formulas given in first-order logic (= predicate calculus); predicates typically refer to program variables. S sat R holds if, whenever program is started in state satisfying first predicate and program terminates, the final state satisfies the second predicate. Verification conducted using proof rules. The logic is sometimes called Floyd-Hoare logic and dates back to a paper by Hoare in It was a very active topic of research in 70s and 80s for sequential and parallel programs.

5 CMSC 630 February 11, The GC Programming Language Systems in Hoare Logic are given as programs in a small programming language called GC (for guarded commands).. We assume existence of following sets. Var: Program variables (assume integer-valued). AE: Arithmetic expressions built using constants, variables, operators, etc. (e.g x + 1) BE: Boolean expressions (e.g. x = 0,(y = 0) (x = 2)). Note Together with definitions offv AE,BE and subst, we have the syntactic component of a data theory: Z, Var, AE, BE,FV AE,BE, subst (Z = {..., 1,0,1,...} is the set of integers.)

6 CMSC 630 February 11, GC Statements Letv 1,... Var,e 1,... AE, andg 1,... BE. Then the setsof GC statements is defined as follows. S ::= skip no-op halt abort v 1,...,v n :=e 1,...,e n assignment (*) S; S sequential composition if G 1 S... G n S fi alternative composition do G 1 S... G n S od iteration (*) Inv 1,...,v n := e 1,...,e n, there is an additional syntactic restriction: ifi j thenv i v j (i.e. v i andv j must be different variables).

7 CMSC 630 February 11, Semantics of GC To treat GC programs mathematically, they must be given a mathematical meaning, or semantics. There are different ways to do this. Denotational. Programs are defined as functions mapping states (initial values of variables) to (sets of) states. Operational. Programs defined in terms of how they execute. Our semantics of GC will be an operational semantics given in the Structural Operational Semantics (SOS) style developed by Scottish computer scientist Gordon Plotkin in the early 80s. He only published a peer-reviewed paper on the subject in 2004; results previously available in 1981 Aarhus University (Denmark) technical report (Tech. Rep. DAIMI FN-19). SOS relies on specifying operational semantics using inference rules. Two types of SOS specifications: evaluation ( big-step ) defines what programs evaluate to, while transition ( small-step ) defines a program s atomic execution steps.

8 CMSC 630 February 11, A Big-Step SOS for GC The big-step SOS for GC will involve defining a relation= (S Σ) Σ, whereσis the set of program states defined below. Intuitively, S,σ = σ holds when statements, starting in stateσ, is able to terminate in stateσ. Definition Σ, the set of states, is defined as the set of mappings Var Z.

9 CMSC 630 February 11, Defining= for GC The evaluation relation = for GC is defined inductively using inference rules. Premises of rules will typically involve evaluation of subexpressions. Conclusion will define evaluation of over-all statement, given premises. Assumptions: A function[[ ]] AE AE Σ Z;[[e]] AE (σ) returns the value ofein stateσ. A relation = BE Σ BE;σ = BE G holds when G is true in stateσ. State updating can be generalized as follows: ifσ Σ andv 1,...,v n,k 1,...,k n are sequences of variables/integers with the property that ifi j, thenv i v j, then k i ifx = v i (σ[v 1 k 1,,v n k n ])(x) = σ(x) otherwise Note [[ ]] AE, = BE is the semantic part of the data theory of program expressions!

10 CMSC 630 February 11, Defining = : Rules (1/2) skip,σ = σ (skip) k 1 = [[e 1 ]] AE (σ)... k n = [[e n ]] AE (σ) v 1,...,v n :=e 1,...,e n,σ = σ[v 1 k 1,...,v n k n ] (:=) S 1,σ = σ S 2,σ = σ S 1 ;S 2,σ = σ (;) σ = BE G i S i,σ = σ if G 1 S 1... G n S n fi,σ = σ (if)

11 CMSC 630 February 11, Defining = : Rules (2/2) σ = BE G 1... σ = BE G n do G 1 S 1 G n S n od,σ = σ (do 1 ) σ = BE G i S i,σ = σ do G 1 S 1 G n S n od,σ = σ do G 1 S 1 G n S n od,σ = σ (do 2 ) Notes There are no rules for halt! This means there can be no statesσ,σ such that halt,σ = σ. Implication: halt does not terminate. if fi does not terminate if all the guards are false in a given state. (Why?) if fi and do od can give rise to nondeterminism. (How?) Notation IfS S andσ Σ then[[s]](σ) = {σ Σ S,σ = σ }.

12 CMSC 630 February 11, State Predicates In Hoare Logic we now definesys = S. What aboutspec? Program specifications will involve first-order formulas (sometimes called state predicates in the literature). What are state predicates? First-order logical formulas over the data theory of program expressions (i.e. AE, BE, etc.). Examples 1. x < 3 2. j Z. 0 j < i (min A[j]) LetΦbe the set of state predicates. The semantics of state predicates is the usual one for first-order logic a relation = Σ Φ, whereσ = φ means φ is true in stateσ.

13 CMSC 630 February 11, Specifications in Hoare Logic We can now define the set of specifications in Hoare Logic. In a specification P, Q : Spec = Φ Φ P is called the precondition. Q is called the postcondition.

14 CMSC 630 February 11, The Satisfaction Relation in Hoare Logic The third component in the Hoare Logic verification framework is sat : when does a program satisfy a specification? Definition Let S be a program (statement), P, Q be a precondition/postcondition pair. Then S sat P,Q if and only if, for everyσ,σ such that thatσ = P and S,σ = σ,σ = Q. Terminology Judgments in Hoare Logic are called Hoare triples and are written {P}S {Q}. A Hoare triple{p}s {Q} is valid if it is the case thats sat P,Q. Note The notation of satisfaction here is called partial correctness, because programs are not required to terminate. Total correctness imposes an additional termination requirement.

15 CMSC 630 February 11, Proving the Validity of Hoare Triples We have now defined the Hoare Logic verification framework. How do we now verify programs? Traditional approach relies on proofs using a collection of inference rules. Rules have form premises conclusion (name), premises is a list of judgments and first-order statements (i.e. elements of Φ!), and conclusion is a judgment. If a rule has no hypotheses, it is sometimes called an axiom. A rule encodes a single step of reasoning and can be applied once its premises have been proved. Notation IfP Φ,v 1,... Var,e 1,... AE thenp v 1,...,v n e 1,...,e n is Hoare-speak for (simultaneous) substitution of eachv i bye i inp.

16 CMSC 630 February 11, Axioms of Hoare Logic {P} skip{p} (skip) {P} halt{q} (halt) {P v 1,...,v n e 1,...,e n }v 1,...,v n :=e 1,...,e n {P} (:=)

17 CMSC 630 February 11, Inference Rules of Hoare Logic: Program Constructs {P}S 1 {Q} {P}S 1 ;S 2 {R} {Q}S 2 {R} (;) {P G 1 }S 1 {Q} {P G n }S n {Q} {P} if G 1 S 1 G n S n fi{q} (if) {I G 1 }S 1 {I} {I G n }S n {I} {I} do G 1 S 1 G n S n od{i G 1 G n } (do) Note In Rule(do), state predicate I is often called a loop invariant.

18 CMSC 630 February 11, Inference Rules of Hoare Logic: State Predicate Reasoning P P {P}S {Q} Q Q {P }S {Q } ( ) Note In this rule,p P andq Q are intended tautologies. They must be proven using a proof system for first-order logic (i.e. not using Hoare Logic).

19 CMSC 630 February 11, Example Consider the following program Pr, which should calculate the quotient and remainder of dividing x by y. r, q := x, 0; do y r r, q := r-y, q+1 od We would like to prove {x 0} Pr{x = q y+r 0 r < y} In what follows, definei = (x = q y+r 0 r).

20 CMSC 630 February 11, Example (cont.) Recall I = (x = q y+r 0 r) {x = (q+1) y+r y 0 (r y)} r,q := r y,q+1 {I} (:=) (1) (I (y r)) (x = (q+1) y+(r y) 0 (r y)) (2) {I (y r)} r,q := r y,q+1 {I} ( )2,1 (3) {I} do...od {I (y > r)} (do)3 (4) {x = 0 y+x (0 x)} r,q := x,0 {I} (:=) (5) x 0 ((x = 0 y+x) (0 x)) (6) {x 0} r,q := x,0 {I} ( )5,6 (7) {x 0} r,q := x,0; do...od {I (y > r)} (;)7,4 (8) (I (y > r)) (x = q y+r 0 r < y) (9) {x 0} Pr {(x = q y+r 0 r < y} ( )8,9(10)

21 CMSC 630 February 11, Reasoning in Practice: Proof Outlines Proofs are usually given as proof outlines. 1. State predicates are inserted into program text so that every statement (simple and compound) has a pre- and postcondition. 2. A proof outline is valid if every embedded triple is valid and adjacent predicates related by implication. {x 0} {x = 0 y+x 0 x} r, q := x, 0; {I} do y r {I y r} od {I y > r} {x = q y+r 0 r < y} r, q := r-y, q+1 {I}

22 CMSC 630 February 11, Formal Definition of Set P of Proof Outlines Given inductively! In the following rules,r,r 1,... are partial proof outlines: R S may be a program; or R = {P}S may be a program with a precondition (S S); or R = S{Q} may be a program with a postcondition (S S); or R P may be a full proof outline.

23 CMSC 630 February 11, Inductive Definition of P {P} skip {P} P {P v 1,...,v n e 1,...,e n }v 1,...,v n := e 1,...,e n {P} P {P}R 1 {P } P {P }R 2 {Q} P {P}R 1 ;{P }R 2 {Q} P {P G 1 }R 1 {Q} P {P G n }R n {Q} P {P} if G 1 {P G 1 }R 1 {Q} G n {P G n }R n {Q} fi{q} P {I G 1 }R 1 {I} P {I G n }R n {I} P {I} do G 1 {I G 1 }R 1 {I} G n {I G n }R n {I} od{i i G i} P P P {P}R{Q} P {P }{P}R{Q} P {P}R{Q} P Q Q {P}R{Q}{Q } P

24 CMSC 630 February 11, Reasoning in Practice: Where do Preconditions Come from? Begin by capturing as a postconditionqwhat the result of the programs should be. Use axioms and inference rules to reason backwards to obtain a preconditionp fors. Result is a of the triple{p}s {Q}. This idea can be formalized via weakest liberal preconditions. First, we can associate a set of states with any state predicate as follows. Definition Letφ Φ be a state predicate. Then[[φ]] = {σ Σ σ = φ} Definition LetS be a statement andφ Φ be a state predicate. Then the weakest liberal precondition, wlp(s,φ) ofs with respect toφis given by: wlp(s,φ) = {σ Σ [[S]](σ) [[φ]]}

25 CMSC 630 February 11, Weakest Liberal Preconditions Can Be Computed Syntactically! Edsger Dijkstra initiated study on this problem in Theorem LetS be a program andφastate predicate. Then the following hold. 1. wlp(skip,φ) = [[φ]] 2. wlp(halt,φ) = Σ = [[tt]] 3. wlp(v 1,...,v n :=e 1,...,e n,φ) = [[φ v 1,...,v n e 1,...,e n ]] 4. wlp(s 1 ;S 2,φ) = wlp(s 1, wlp(s 2,φ)) 5. wlp(if G 1 S 1 G n S n fi,φ) = ([[ G 1 ]] wlp(s 1,φ)) ([[ G n ]] wlp(s n,φ)) Note In (5)[[ G i ]] wlp(s i,φ) may be seen as equivalent to G i wlp(s i,φ). What about do od?

26 CMSC 630 February 11, wlp and do wlp(do od,φ) may be represented syntactically in theory, but it is impractical to compute (relies on encoding computations of while loops as integers). We can come close, however. Fact LetD = do G 1 S 1 G n S n od. Then [[D]](σ) = [[if G 1 (S 1 ;D) G n (S n ;D) (G 1 G n ) skip fi]](σ) In other words,[[d]] is a solution to a recursive equation involving if fi. Given D, φ, consider the following. H 0 = [[tt]] = Σ H j = ([[ G1 ]] wlp(s 1,H j 1 )) ([[ G n ]] wlp(s n,h j 1 )) ([[( (G 1 G n )) φ]]) Fact wlp(d,φ) = j 0 H j Why is this close, but not necessarily the answer? Because obvious approach to representing theh j falls outside the syntax of first-order logic.

27 CMSC 630 February 11, Reasoning in Practice: Loop Invariants The inference rule for do-loops requires the creation of a loop invariant which must hold each time through the loop. Coming up with the right loop invariants is often the trickiest aspect of sequential program verification. General strategy: weaken postcondition of loop, by e.g. deleting conjuncts, replacing constant with variable, etc. Gries book, Chapter 16, has good tips and examples. Invariants generally capture design information and are very useful as documentation, even if you don t prove your programs correct.

28 CMSC 630 February 11, Soundness and Relative Completeness Recall soundess and completeness. Soundness: Can only valid things be proved? Completeness: Can all valid things be proved? We can study these issues for Hoare Logic! Theorem (Soundness) Suppose{P} S {Q} is provable. Then it is valid. Theorem (Relative Completeness) Suppose that there is a complete proof system for establishingp Q. Then the validity of{p}s {Q} implies{p}s {Q} is provable. Question Why is only relative completeness possible, in general?

Hoare Logic (I): Axiomatic Semantics and Program Correctness

Hoare Logic (I): Axiomatic Semantics and Program Correctness Hoare Logic (I): Axiomatic Semantics and Program Correctness (Based on [Apt and Olderog 1991; Gries 1981; Hoare 1969; Kleymann 1999; Sethi 199]) Yih-Kuen Tsay Dept. of Information Management National Taiwan

More information

Axiomatic Semantics. Semantics of Programming Languages course. Joosep Rõõmusaare

Axiomatic Semantics. Semantics of Programming Languages course. Joosep Rõõmusaare Axiomatic Semantics Semantics of Programming Languages course Joosep Rõõmusaare 2014 Direct Proofs of Program Correctness Partial correctness properties are properties expressing that if a given program

More information

Classical Program Logics: Hoare Logic, Weakest Liberal Preconditions

Classical Program Logics: Hoare Logic, Weakest Liberal Preconditions Chapter 1 Classical Program Logics: Hoare Logic, Weakest Liberal Preconditions 1.1 The IMP Language IMP is a programming language with an extensible syntax that was developed in the late 1960s. We will

More information

Axiomatic Semantics. Lecture 9 CS 565 2/12/08

Axiomatic Semantics. Lecture 9 CS 565 2/12/08 Axiomatic Semantics Lecture 9 CS 565 2/12/08 Axiomatic Semantics Operational semantics describes the meaning of programs in terms of the execution steps taken by an abstract machine Denotational semantics

More information

Dynamic Semantics. Dynamic Semantics. Operational Semantics Axiomatic Semantics Denotational Semantic. Operational Semantics

Dynamic Semantics. Dynamic Semantics. Operational Semantics Axiomatic Semantics Denotational Semantic. Operational Semantics Dynamic Semantics Operational Semantics Denotational Semantic Dynamic Semantics Operational Semantics Operational Semantics Describe meaning by executing program on machine Machine can be actual or simulated

More information

Propositional and Predicate Logic. jean/gbooks/logic.html

Propositional and Predicate Logic.   jean/gbooks/logic.html CMSC 630 February 10, 2009 1 Propositional and Predicate Logic Sources J. Gallier. Logic for Computer Science, John Wiley and Sons, Hoboken NJ, 1986. 2003 revised edition available on line at http://www.cis.upenn.edu/

More information

The Assignment Axiom (Hoare)

The Assignment Axiom (Hoare) The Assignment Axiom (Hoare) Syntax: V := E Semantics: value of V in final state is value of E in initial state Example: X:=X+ (adds one to the value of the variable X) The Assignment Axiom {Q[E/V ]} V

More information

Programming Languages and Compilers (CS 421)

Programming Languages and Compilers (CS 421) Programming Languages and Compilers (CS 421) Sasa Misailovic 4110 SC, UIUC https://courses.engr.illinois.edu/cs421/fa2017/cs421a Based in part on slides by Mattox Beckman, as updated by Vikram Adve, Gul

More information

Spring 2015 Program Analysis and Verification. Lecture 4: Axiomatic Semantics I. Roman Manevich Ben-Gurion University

Spring 2015 Program Analysis and Verification. Lecture 4: Axiomatic Semantics I. Roman Manevich Ben-Gurion University Spring 2015 Program Analysis and Verification Lecture 4: Axiomatic Semantics I Roman Manevich Ben-Gurion University Agenda Basic concepts of correctness Axiomatic semantics (pages 175-183) Hoare Logic

More information

Spring 2016 Program Analysis and Verification. Lecture 3: Axiomatic Semantics I. Roman Manevich Ben-Gurion University

Spring 2016 Program Analysis and Verification. Lecture 3: Axiomatic Semantics I. Roman Manevich Ben-Gurion University Spring 2016 Program Analysis and Verification Lecture 3: Axiomatic Semantics I Roman Manevich Ben-Gurion University Warm-up exercises 1. Define program state: 2. Define structural semantics configurations:

More information

Hoare Logic: Reasoning About Imperative Programs

Hoare Logic: Reasoning About Imperative Programs Hoare Logic: Reasoning About Imperative Programs COMP1600 / COMP6260 Dirk Pattinson Australian National University Semester 2, 2018 Programming Paradigms Functional. (Haskell, SML, OCaml,... ) main paradigm:

More information

Program Analysis Part I : Sequential Programs

Program Analysis Part I : Sequential Programs Program Analysis Part I : Sequential Programs IN5170/IN9170 Models of concurrency Program Analysis, lecture 5 Fall 2018 26. 9. 2018 2 / 44 Program correctness Is my program correct? Central question for

More information

Program verification. Hoare triples. Assertional semantics (cont) Example: Semantics of assignment. Assertional semantics of a program

Program verification. Hoare triples. Assertional semantics (cont) Example: Semantics of assignment. Assertional semantics of a program Program verification Assertional semantics of a program Meaning of a program: relation between its inputs and outputs; specified by input assertions (pre-conditions) and output assertions (post-conditions)

More information

Axiomatic semantics. Semantics and Application to Program Verification. Antoine Miné. École normale supérieure, Paris year

Axiomatic semantics. Semantics and Application to Program Verification. Antoine Miné. École normale supérieure, Paris year Axiomatic semantics Semantics and Application to Program Verification Antoine Miné École normale supérieure, Paris year 2015 2016 Course 6 18 March 2016 Course 6 Axiomatic semantics Antoine Miné p. 1 /

More information

Learning Goals of CS245 Logic and Computation

Learning Goals of CS245 Logic and Computation Learning Goals of CS245 Logic and Computation Alice Gao April 27, 2018 Contents 1 Propositional Logic 2 2 Predicate Logic 4 3 Program Verification 6 4 Undecidability 7 1 1 Propositional Logic Introduction

More information

Hoare Logic I. Introduction to Deductive Program Verification. Simple Imperative Programming Language. Hoare Logic. Meaning of Hoare Triples

Hoare Logic I. Introduction to Deductive Program Verification. Simple Imperative Programming Language. Hoare Logic. Meaning of Hoare Triples Hoare Logic I Introduction to Deductive Program Verification Işıl Dillig Program Spec Deductive verifier FOL formula Theorem prover valid contingent Example specs: safety (no crashes), absence of arithmetic

More information

Axiomatic Semantics. Stansifer Ch 2.4, Ch. 9 Winskel Ch.6 Slonneger and Kurtz Ch. 11 CSE

Axiomatic Semantics. Stansifer Ch 2.4, Ch. 9 Winskel Ch.6 Slonneger and Kurtz Ch. 11 CSE Axiomatic Semantics Stansifer Ch 2.4, Ch. 9 Winskel Ch.6 Slonneger and Kurtz Ch. 11 CSE 6341 1 Outline Introduction What are axiomatic semantics? First-order logic & assertions about states Results (triples)

More information

Deterministic Program The While Program

Deterministic Program The While Program Deterministic Program The While Program Shangping Ren Department of Computer Science Illinois Institute of Technology February 24, 2014 Shangping Ren Deterministic Program The While Program February 24,

More information

Program verification using Hoare Logic¹

Program verification using Hoare Logic¹ Program verification using Hoare Logic¹ Automated Reasoning - Guest Lecture Petros Papapanagiotou Part 2 of 2 ¹Contains material from Mike Gordon s slides: Previously on Hoare Logic A simple while language

More information

Reasoning About Imperative Programs. COS 441 Slides 10b

Reasoning About Imperative Programs. COS 441 Slides 10b Reasoning About Imperative Programs COS 441 Slides 10b Last time Hoare Logic: { P } C { Q } Agenda If P is true in the initial state s. And C in state s evaluates to s. Then Q must be true in s. Program

More information

COMP2111 Glossary. Kai Engelhardt. Contents. 1 Symbols. 1 Symbols 1. 2 Hoare Logic 3. 3 Refinement Calculus 5. rational numbers Q, real numbers R.

COMP2111 Glossary. Kai Engelhardt. Contents. 1 Symbols. 1 Symbols 1. 2 Hoare Logic 3. 3 Refinement Calculus 5. rational numbers Q, real numbers R. COMP2111 Glossary Kai Engelhardt Revision: 1.3, May 18, 2018 Contents 1 Symbols 1 2 Hoare Logic 3 3 Refinement Calculus 5 1 Symbols Booleans B = {false, true}, natural numbers N = {0, 1, 2,...}, integers

More information

Program verification. 18 October 2017

Program verification. 18 October 2017 Program verification 18 October 2017 Example revisited // assume(n>2); void partition(int a[], int n) { int pivot = a[0]; int lo = 1, hi = n-1; while (lo

More information

Program Analysis and Verification

Program Analysis and Verification Program Analysis and Verification 0368-4479 Noam Rinetzky Lecture 4: Axiomatic Semantics Slides credit: Tom Ball, Dawson Engler, Roman Manevich, Erik Poll, Mooly Sagiv, Jean Souyris, Eran Tromer, Avishai

More information

Lecture Notes: Axiomatic Semantics and Hoare-style Verification

Lecture Notes: Axiomatic Semantics and Hoare-style Verification Lecture Notes: Axiomatic Semantics and Hoare-style Verification 17-355/17-665/17-819O: Program Analysis (Spring 2018) Claire Le Goues and Jonathan Aldrich clegoues@cs.cmu.edu, aldrich@cs.cmu.edu It has

More information

Marie Farrell Supervisors: Dr Rosemary Monahan & Dr James Power Principles of Programming Research Group

Marie Farrell Supervisors: Dr Rosemary Monahan & Dr James Power Principles of Programming Research Group EXAMINING REFINEMENT: THEORY, TOOLS AND MATHEMATICS Marie Farrell Supervisors: Dr Rosemary Monahan & Dr James Power Principles of Programming Research Group PROBLEM Different formalisms do not integrate

More information

Hoare Logic and Model Checking

Hoare Logic and Model Checking Hoare Logic and Model Checking Kasper Svendsen University of Cambridge CST Part II 2016/17 Acknowledgement: slides heavily based on previous versions by Mike Gordon and Alan Mycroft Introduction In the

More information

Floyd-Hoare Style Program Verification

Floyd-Hoare Style Program Verification Floyd-Hoare Style Program Verification Deepak D Souza Department of Computer Science and Automation Indian Institute of Science, Bangalore. 9 Feb 2017 Outline of this talk 1 Overview 2 Hoare Triples 3

More information

Solutions to exercises for the Hoare logic (based on material written by Mark Staples)

Solutions to exercises for the Hoare logic (based on material written by Mark Staples) Solutions to exercises for the Hoare logic (based on material written by Mark Staples) Exercise 1 We are interested in termination, so that means we need to use the terminology of total correctness, i.e.

More information

Lecture 2: Axiomatic semantics

Lecture 2: Axiomatic semantics Chair of Software Engineering Trusted Components Prof. Dr. Bertrand Meyer Lecture 2: Axiomatic semantics Reading assignment for next week Ariane paper and response (see course page) Axiomatic semantics

More information

COP4020 Programming Languages. Introduction to Axiomatic Semantics Prof. Robert van Engelen

COP4020 Programming Languages. Introduction to Axiomatic Semantics Prof. Robert van Engelen COP4020 Programming Languages Introduction to Axiomatic Semantics Prof. Robert van Engelen Assertions and Preconditions Assertions are used by programmers to verify run-time execution An assertion is a

More information

CSC 7101: Programming Language Structures 1. Axiomatic Semantics. Stansifer Ch 2.4, Ch. 9 Winskel Ch.6 Slonneger and Kurtz Ch. 11.

CSC 7101: Programming Language Structures 1. Axiomatic Semantics. Stansifer Ch 2.4, Ch. 9 Winskel Ch.6 Slonneger and Kurtz Ch. 11. Axiomatic Semantics Stansifer Ch 2.4, Ch. 9 Winskel Ch.6 Slonneger and Kurtz Ch. 11 1 Overview We ll develop proof rules, such as: { I b } S { I } { I } while b do S end { I b } That allow us to verify

More information

Logic. Propositional Logic: Syntax

Logic. Propositional Logic: Syntax Logic Propositional Logic: Syntax Logic is a tool for formalizing reasoning. There are lots of different logics: probabilistic logic: for reasoning about probability temporal logic: for reasoning about

More information

Introduction to Axiomatic Semantics

Introduction to Axiomatic Semantics #1 Introduction to Axiomatic Semantics #2 How s The Homework Going? Remember that you can t just define a meaning function in terms of itself you must use some fixed point machinery. #3 Observations A

More information

Hoare Calculus and Predicate Transformers

Hoare Calculus and Predicate Transformers Hoare Calculus and Predicate Transformers Wolfgang Schreiner Wolfgang.Schreiner@risc.uni-linz.ac.at Research Institute for Symbolic Computation (RISC) Johannes Kepler University, Linz, Austria http://www.risc.uni-linz.ac.at

More information

A Short Introduction to Hoare Logic

A Short Introduction to Hoare Logic A Short Introduction to Hoare Logic Supratik Chakraborty I.I.T. Bombay June 23, 2008 Supratik Chakraborty (I.I.T. Bombay) A Short Introduction to Hoare Logic June 23, 2008 1 / 34 Motivation Assertion checking

More information

Hoare Logic: Part II

Hoare Logic: Part II Hoare Logic: Part II COMP2600 Formal Methods for Software Engineering Jinbo Huang Australian National University COMP 2600 Hoare Logic II 1 Factorial {n 0} fact := 1; i := n; while (i >0) do fact := fact

More information

Control Predicates Are Better Than Dummy Variables For Reasoning About Program Control

Control Predicates Are Better Than Dummy Variables For Reasoning About Program Control Control Predicates Are Better Than Dummy Variables For Reasoning About Program Control LESLIE LAMPORT Digital Equipment Corporation When explicit control predicates rather than dummy variables are used,

More information

Last Time. Inference Rules

Last Time. Inference Rules Last Time When program S executes it switches to a different state We need to express assertions on the states of the program S before and after its execution We can do it using a Hoare triple written

More information

Bilateral Proofs of Safety and Progress Properties of Concurrent Programs (Working Draft)

Bilateral Proofs of Safety and Progress Properties of Concurrent Programs (Working Draft) Bilateral Proofs of Safety and Progress Properties of Concurrent Programs (Working Draft) Jayadev Misra December 18, 2015 Contents 1 Introduction 3 2 Program and Execution Model 4 2.1 Program Structure..........................

More information

Proof Rules for Correctness Triples

Proof Rules for Correctness Triples Proof Rules for Correctness Triples CS 536: Science of Programming, Fall 2018 A. Why? We can t generally prove that correctness triples are valid using truth tables. We need proof axioms for atomic statements

More information

What happens to the value of the expression x + y every time we execute this loop? while x>0 do ( y := y+z ; x := x:= x z )

What happens to the value of the expression x + y every time we execute this loop? while x>0 do ( y := y+z ; x := x:= x z ) Starter Questions Feel free to discuss these with your neighbour: Consider two states s 1 and s 2 such that s 1, x := x + 1 s 2 If predicate P (x = y + 1) is true for s 2 then what does that tell us about

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2017 Lecture 2b Andrew Tolmach Portland State University 1994-2017 Semantics Informal vs. Formal Informal semantics Descriptions in English (or other natural language)

More information

Deductive Verification

Deductive Verification Deductive Verification Mooly Sagiv Slides from Zvonimir Rakamaric First-Order Logic A formal notation for mathematics, with expressions involving Propositional symbols Predicates Functions and constant

More information

Weakest Precondition Calculus

Weakest Precondition Calculus Weakest Precondition Calculus COMP2600 Formal Methods for Software Engineering Rajeev Goré Australian National University Semester 2, 2016 (Most lecture slides due to Ranald Clouston) COMP 2600 Weakest

More information

Propositional Logic: Syntax

Propositional Logic: Syntax Logic Logic is a tool for formalizing reasoning. There are lots of different logics: probabilistic logic: for reasoning about probability temporal logic: for reasoning about time (and programs) epistemic

More information

Hoare Logic: Reasoning About Imperative Programs

Hoare Logic: Reasoning About Imperative Programs Hoare Logic: Reasoning About Imperative Programs COMP1600 / COMP6260 Dirk Pattinson Australian National University Semester 2, 2017 Catch Up / Drop in Lab When Fridays, 15.00-17.00 Where N335, CSIT Building

More information

Axiomatic Semantics. Hoare s Correctness Triplets Dijkstra s Predicate Transformers

Axiomatic Semantics. Hoare s Correctness Triplets Dijkstra s Predicate Transformers Axiomatic Semantics Hoare s Correctness Triplets Dijkstra s Predicate Transformers Goal of a program = IO Relation Problem Specification Properties satisfied by the input and expected of the output (usually

More information

Axiomatic Semantics. Operational semantics. Good for. Not good for automatic reasoning about programs

Axiomatic Semantics. Operational semantics. Good for. Not good for automatic reasoning about programs Review Operational semantics relatively l simple many flavors (small vs. big) not compositional (rule for while) Good for describing language implementation reasoning about properties of the language eg.

More information

Axiomatic Semantics: Verification Conditions. Review of Soundness and Completeness of Axiomatic Semantics. Announcements

Axiomatic Semantics: Verification Conditions. Review of Soundness and Completeness of Axiomatic Semantics. Announcements Axiomatic Semantics: Verification Conditions Meeting 12, CSCI 5535, Spring 2009 Announcements Homework 4 is due tonight Wed forum: papers on automated testing using symbolic execution 2 Questions? Review

More information

In this episode of The Verification Corner, Rustan Leino talks about Loop Invariants. He gives a brief summary of the theoretical foundations and

In this episode of The Verification Corner, Rustan Leino talks about Loop Invariants. He gives a brief summary of the theoretical foundations and In this episode of The Verification Corner, Rustan Leino talks about Loop Invariants. He gives a brief summary of the theoretical foundations and shows how a program can sometimes be systematically constructed

More information

Proof Calculus for Partial Correctness

Proof Calculus for Partial Correctness Proof Calculus for Partial Correctness Bow-Yaw Wang Institute of Information Science Academia Sinica, Taiwan September 7, 2016 Bow-Yaw Wang (Academia Sinica) Proof Calculus for Partial Correctness September

More information

Strength; Weakest Preconditions

Strength; Weakest Preconditions 12/14: solved Strength; Weakest Preconditions CS 536: Science of Programming, Spring 2018 A. Why To combine correctness triples, we need to weaken and strengthen conditions. A weakest precondition is the

More information

A Humble Introduction to DIJKSTRA S A A DISCIPLINE OF PROGRAMMING

A Humble Introduction to DIJKSTRA S A A DISCIPLINE OF PROGRAMMING A Humble Introduction to DIJKSTRA S A A DISCIPLINE OF PROGRAMMING Do-Hyung Kim School of Computer Science and Engineering Sungshin Women s s University CONTENTS Bibliographic Information and Organization

More information

Logic. Propositional Logic: Syntax. Wffs

Logic. Propositional Logic: Syntax. Wffs Logic Propositional Logic: Syntax Logic is a tool for formalizing reasoning. There are lots of different logics: probabilistic logic: for reasoning about probability temporal logic: for reasoning about

More information

Formal Methods in Software Engineering

Formal Methods in Software Engineering Formal Methods in Software Engineering An Introduction to Model-Based Analyis and Testing Vesal Vojdani Department of Computer Science University of Tartu Fall 2014 Vesal Vojdani (University of Tartu)

More information

Probabilistic Guarded Commands Mechanized in HOL

Probabilistic Guarded Commands Mechanized in HOL Probabilistic Guarded Commands Mechanized in HOL Joe Hurd joe.hurd@comlab.ox.ac.uk Oxford University Joint work with Annabelle McIver (Macquarie University) and Carroll Morgan (University of New South

More information

arxiv: v1 [cs.pl] 5 Apr 2017

arxiv: v1 [cs.pl] 5 Apr 2017 arxiv:1704.01814v1 [cs.pl] 5 Apr 2017 Bilateral Proofs of Safety and Progress Properties of Concurrent Programs Jayadev Misra University of Texas at Austin, misra@utexas.edu April 5, 2017 Abstract This

More information

Verifying Properties of Parallel Programs: An Axiomatic Approach

Verifying Properties of Parallel Programs: An Axiomatic Approach Verifying Properties of Parallel Programs: An Axiomatic Approach By Susan Owicki and David Gries (1976) Nathan Wetzler nwetzler@cs.utexas.edu University of Texas, Austin November 3, 2009 Outline Introduction

More information

Spring 2014 Program Analysis and Verification. Lecture 6: Axiomatic Semantics III. Roman Manevich Ben-Gurion University

Spring 2014 Program Analysis and Verification. Lecture 6: Axiomatic Semantics III. Roman Manevich Ben-Gurion University Spring 2014 Program Analysis and Verification Lecture 6: Axiomatic Semantics III Roman Manevich Ben-Gurion University Syllabus Semantics Static Analysis Abstract Interpretation fundamentals Analysis Techniques

More information

Calculating axiomatic semantics from program equations by means of functional predicate calculus

Calculating axiomatic semantics from program equations by means of functional predicate calculus Calculating axiomatic semantics from program equations by means of functional predicate calculus (Some initial results of recent work not for dissemination) Raymond Boute INTEC Ghent University 2004/02

More information

Introduction to Kleene Algebra Lecture 14 CS786 Spring 2004 March 15, 2004

Introduction to Kleene Algebra Lecture 14 CS786 Spring 2004 March 15, 2004 Introduction to Kleene Algebra Lecture 14 CS786 Spring 2004 March 15, 2004 KAT and Hoare Logic In this lecture and the next we show that KAT subsumes propositional Hoare logic (PHL). Thus the specialized

More information

Examples: P: it is not the case that P. P Q: P or Q P Q: P implies Q (if P then Q) Typical formula:

Examples: P: it is not the case that P. P Q: P or Q P Q: P implies Q (if P then Q) Typical formula: Logic: The Big Picture Logic is a tool for formalizing reasoning. There are lots of different logics: probabilistic logic: for reasoning about probability temporal logic: for reasoning about time (and

More information

Foundations of Quantum Programming

Foundations of Quantum Programming Foundations of Quantum Programming Mingsheng Ying University of Technology Sydney, Australia Institute of Software, Chinese Academy of Sciences Tsinghua University, China Outline Introduction Syntax of

More information

Extending the theory of Owicki and Gries with a logic of progress

Extending the theory of Owicki and Gries with a logic of progress Extending the theory of Owicki and Gries with a logic of progress Brijesh Dongol Doug Goldson August 2005 Technical Report SSE-2005-03 Division of Systems and Software Engineering Research School of Information

More information

Unifying Theories of Programming

Unifying Theories of Programming 1&2 Unifying Theories of Programming Unifying Theories of Programming 3&4 Theories Unifying Theories of Programming designs predicates relations reactive CSP processes Jim Woodcock University of York May

More information

Proofs of Correctness: Introduction to Axiomatic Verification

Proofs of Correctness: Introduction to Axiomatic Verification Proofs of Correctness: Introduction to Axiomatic Verification Introduction Weak correctness predicate Assignment statements Sequencing Selection statements Iteration 1 Introduction What is Axiomatic Verification?

More information

Verification Using Temporal Logic

Verification Using Temporal Logic CMSC 630 February 25, 2015 1 Verification Using Temporal Logic Sources: E.M. Clarke, O. Grumberg and D. Peled. Model Checking. MIT Press, Cambridge, 2000. E.A. Emerson. Temporal and Modal Logic. Chapter

More information

What? Correctness? Bugs!

What? Correctness? Bugs! Program Correctness Literatuur Verification of Sequential and Concurrent Programs. Krzysztof R. Apt, Frank S. de Boer, Ernst-Rüdiger Olderog. Series: Texts in Computer Science. Springer. 3rd ed. 2nd Printing.

More information

Reasoning by Regression: Pre- and Postdiction Procedures for Logics of Action and Change with Nondeterminism*

Reasoning by Regression: Pre- and Postdiction Procedures for Logics of Action and Change with Nondeterminism* Reasoning by Regression: Pre- and Postdiction Procedures for Logics of Action and Change with Nondeterminism* Marcus Bjareland and Lars Karlsson Department of Computer and Information Science Linkopings

More information

Soundness and Completeness of Axiomatic Semantics

Soundness and Completeness of Axiomatic Semantics #1 Soundness and Completeness of Axiomatic Semantics #2 One-Slide Summary A system of axiomatic semantics is sound if everything we can prove is also true: if ` { A } c { B } then ² { A } c { B } We prove

More information

Software Engineering

Software Engineering Software Engineering Lecture 07: Design by Contract Peter Thiemann University of Freiburg, Germany 02.06.2014 Table of Contents Design by Contract Contracts for Procedural Programs Contracts for Object-Oriented

More information

First Order Logic vs Propositional Logic CS477 Formal Software Dev Methods

First Order Logic vs Propositional Logic CS477 Formal Software Dev Methods First Order Logic vs Propositional Logic CS477 Formal Software Dev Methods Elsa L Gunter 2112 SC, UIUC egunter@illinois.edu http://courses.engr.illinois.edu/cs477 Slides based in part on previous lectures

More information

Spring 2015 Program Analysis and Verification. Lecture 6: Axiomatic Semantics III. Roman Manevich Ben-Gurion University

Spring 2015 Program Analysis and Verification. Lecture 6: Axiomatic Semantics III. Roman Manevich Ben-Gurion University Spring 2015 Program Analysis and Verification Lecture 6: Axiomatic Semantics III Roman Manevich Ben-Gurion University Tentative syllabus Semantics Static Analysis Abstract Interpretation fundamentals Analysis

More information

Hoare Examples & Proof Theory. COS 441 Slides 11

Hoare Examples & Proof Theory. COS 441 Slides 11 Hoare Examples & Proof Theory COS 441 Slides 11 The last several lectures: Agenda Denotational semantics of formulae in Haskell Reasoning using Hoare Logic This lecture: Exercises A further introduction

More information

Coinductive big-step semantics and Hoare logics for nontermination

Coinductive big-step semantics and Hoare logics for nontermination Coinductive big-step semantics and Hoare logics for nontermination Tarmo Uustalu, Inst of Cybernetics, Tallinn joint work with Keiko Nakata COST Rich Models Toolkit meeting, Madrid, 17 18 October 2013

More information

The Importance of Being Formal. Martin Henz. February 5, Propositional Logic

The Importance of Being Formal. Martin Henz. February 5, Propositional Logic The Importance of Being Formal Martin Henz February 5, 2014 Propositional Logic 1 Motivation In traditional logic, terms represent sets, and therefore, propositions are limited to stating facts on sets

More information

1 Introduction. 2 First Order Logic. 3 SPL Syntax. 4 Hoare Logic. 5 Exercises

1 Introduction. 2 First Order Logic. 3 SPL Syntax. 4 Hoare Logic. 5 Exercises Contents 1 Introduction INF5140: Lecture 2 Espen H. Lian Institutt for informatikk, Universitetet i Oslo January 28, 2009 2 Proof System 3 SPL 4 GCD 5 Exercises Institutt for informatikk (UiO) INF5140:

More information

Predicate Transforms I

Predicate Transforms I Predicate Transforms I Software Testing and Verification Lecture Notes 19 Prepared by Stephen M. Thebaut, Ph.D. University of Florida Predicate Transforms I 1. Introduction: weakest pre-conditions (wp

More information

CS156: The Calculus of Computation Zohar Manna Autumn 2008

CS156: The Calculus of Computation Zohar Manna Autumn 2008 Page 3 of 52 Page 4 of 52 CS156: The Calculus of Computation Zohar Manna Autumn 2008 Lecturer: Zohar Manna (manna@cs.stanford.edu) Office Hours: MW 12:30-1:00 at Gates 481 TAs: Boyu Wang (wangboyu@stanford.edu)

More information

Programming Languages

Programming Languages CSE 230: Winter 2008 Principles of Programming Languages Lecture 6: Axiomatic Semantics Deriv. Rules for Hoare Logic `{A} c {B} Rules for each language construct ` {A} c 1 {B} ` {B} c 2 {C} ` {A} skip

More information

Program Construction and Reasoning

Program Construction and Reasoning Program Construction and Reasoning Shin-Cheng Mu Institute of Information Science, Academia Sinica, Taiwan 2010 Formosan Summer School on Logic, Language, and Computation June 28 July 9, 2010 1 / 97 Introduction:

More information

On the Complexity of the Reflected Logic of Proofs

On the Complexity of the Reflected Logic of Proofs On the Complexity of the Reflected Logic of Proofs Nikolai V. Krupski Department of Math. Logic and the Theory of Algorithms, Faculty of Mechanics and Mathematics, Moscow State University, Moscow 119899,

More information

Softwaretechnik. Lecture 13: Design by Contract. Peter Thiemann University of Freiburg, Germany

Softwaretechnik. Lecture 13: Design by Contract. Peter Thiemann University of Freiburg, Germany Softwaretechnik Lecture 13: Design by Contract Peter Thiemann University of Freiburg, Germany 25.06.2012 Table of Contents Design by Contract Contracts for Procedural Programs Contracts for Object-Oriented

More information

Softwaretechnik. Lecture 13: Design by Contract. Peter Thiemann University of Freiburg, Germany

Softwaretechnik. Lecture 13: Design by Contract. Peter Thiemann University of Freiburg, Germany Softwaretechnik Lecture 13: Design by Contract Peter Thiemann University of Freiburg, Germany 25.06.2012 Table of Contents Design by Contract Contracts for Procedural Programs Contracts for Object-Oriented

More information

Propositional Logic. Logic. Propositional Logic Syntax. Propositional Logic

Propositional Logic. Logic. Propositional Logic Syntax. Propositional Logic Propositional Logic Reading: Chapter 7.1, 7.3 7.5 [ased on slides from Jerry Zhu, Louis Oliphant and ndrew Moore] Logic If the rules of the world are presented formally, then a decision maker can use logical

More information

Formal Specification and Verification. Specifications

Formal Specification and Verification. Specifications Formal Specification and Verification Specifications Imprecise specifications can cause serious problems downstream Lots of interpretations even with technicaloriented natural language The value returned

More information

Predicate Logic. Xinyu Feng 09/26/2011. University of Science and Technology of China (USTC)

Predicate Logic. Xinyu Feng 09/26/2011. University of Science and Technology of China (USTC) University of Science and Technology of China (USTC) 09/26/2011 Overview Predicate logic over integer expressions: a language of logical assertions, for example x. x + 0 = x Why discuss predicate logic?

More information

CS422 - Programming Language Design

CS422 - Programming Language Design 1 CS422 - Programming Language Design Denotational Semantics Grigore Roşu Department of Computer Science University of Illinois at Urbana-Champaign 2 Denotational semantics, also known as fix-point semantics,

More information

Proving Inter-Program Properties

Proving Inter-Program Properties Unité Mixte de Recherche 5104 CNRS - INPG - UJF Centre Equation 2, avenue de VIGNATE F-38610 GIERES tel : +33 456 52 03 40 fax : +33 456 52 03 50 http://www-verimag.imag.fr Proving Inter-Program Properties

More information

CIS (More Propositional Calculus - 6 points)

CIS (More Propositional Calculus - 6 points) 1 CIS6333 Homework 1 (due Friday, February 1) 1. (Propositional Calculus - 10 points) --------------------------------------- Let P, Q, R range over state predicates of some program. Prove or disprove

More information

Formal Methods for Probabilistic Systems

Formal Methods for Probabilistic Systems 1 Formal Methods for Probabilistic Systems Annabelle McIver Carroll Morgan Source-level program logic Introduction to probabilistic-program logic Systematic presentation via structural induction Layout

More information

Design of Distributed Systems Melinda Tóth, Zoltán Horváth

Design of Distributed Systems Melinda Tóth, Zoltán Horváth Design of Distributed Systems Melinda Tóth, Zoltán Horváth Design of Distributed Systems Melinda Tóth, Zoltán Horváth Publication date 2014 Copyright 2014 Melinda Tóth, Zoltán Horváth Supported by TÁMOP-412A/1-11/1-2011-0052

More information

C241 Homework Assignment 7

C241 Homework Assignment 7 C24 Homework Assignment 7. Prove that for all whole numbers n, n i 2 = n(n + (2n + The proof is by induction on k with hypothesis H(k i 2 = k(k + (2k + base case: To prove H(, i 2 = = = 2 3 = ( + (2 +

More information

Applied Logic. Lecture 1 - Propositional logic. Marcin Szczuka. Institute of Informatics, The University of Warsaw

Applied Logic. Lecture 1 - Propositional logic. Marcin Szczuka. Institute of Informatics, The University of Warsaw Applied Logic Lecture 1 - Propositional logic Marcin Szczuka Institute of Informatics, The University of Warsaw Monographic lecture, Spring semester 2017/2018 Marcin Szczuka (MIMUW) Applied Logic 2018

More information

Iris: Higher-Order Concurrent Separation Logic. Lecture 9: Concurrency Intro and Invariants

Iris: Higher-Order Concurrent Separation Logic. Lecture 9: Concurrency Intro and Invariants 1 Iris: Higher-Order Concurrent Separation Logic Lecture 9: Concurrency Intro and Invariants Lars Birkedal Aarhus University, Denmark November 21, 2017 Overview Earlier: Operational Semantics of λ ref,conc

More information

Propositional Calculus - Hilbert system H Moonzoo Kim CS Division of EECS Dept. KAIST

Propositional Calculus - Hilbert system H Moonzoo Kim CS Division of EECS Dept. KAIST Propositional Calculus - Hilbert system H Moonzoo Kim CS Division of EECS Dept. KAIST moonzoo@cs.kaist.ac.kr http://pswlab.kaist.ac.kr/courses/cs402-07 1 Review Goal of logic To check whether given a formula

More information

REAL-TIME control systems usually consist of some

REAL-TIME control systems usually consist of some 1 A Formal Design Technique for Real-Time Embedded Systems Development using Duration Calculus François Siewe, Dang Van Hung, Hussein Zedan and Antonio Cau Abstract In this paper we present a syntactical

More information

Loop Convergence. CS 536: Science of Programming, Fall 2018

Loop Convergence. CS 536: Science of Programming, Fall 2018 Solved Loop Convergence CS 536: Science of Programming, Fall 2018 A. Why Diverging programs aren t useful, so it s useful to know how to show that loops terminate. B. Objectives At the end of this lecture

More information

Tutorial on Semantics Part I

Tutorial on Semantics Part I Tutorial on Semantics Part I Basic Concepts Prakash Panangaden 1 1 School of Computer Science McGill University on sabbatical leave at Department of Computer Science Oxford University Fields Institute,

More information

Axiomatic Semantics: Verification Conditions. Review of Soundness of Axiomatic Semantics. Questions? Announcements

Axiomatic Semantics: Verification Conditions. Review of Soundness of Axiomatic Semantics. Questions? Announcements Axiomatic Semantics: Verification Conditions Meeting 18, CSCI 5535, Spring 2010 Announcements Homework 6 is due tonight Today s forum: papers on automated testing using symbolic execution Anyone looking

More information