Hoare Logic: Part II
|
|
- Jewel Chandler
- 5 years ago
- Views:
Transcription
1 Hoare Logic: Part II COMP2600 Formal Methods for Software Engineering Jinbo Huang Australian National University COMP 2600 Hoare Logic II 1
2 Factorial {n 0} fact := 1; i := n; while (i >0) do fact := fact * i; i := i -1 {fact = n!} COMP 2600 Hoare Logic II 2
3 First we need a loop invariant P fact := 1; i := n; while (i >0) do fact := fact * i; i := i -1 {fact = n!} After each iteration, fact = n (n 1) (i + 1) P (fact i! = n!) seems plausible However, we want (P i 0) (fact = n!) Take P (fact i! = n! i 0) COMP 2600 Hoare Logic II 3
4 Check P (fact i! = n! i 0) is an invariant That is, {P i > 0} fact := fact * i; i := i-1 {P} By assignment, we have Equivalently, {fact (i 1)! = n! i 1 0} i := i-1 {fact i! = n! i 0} {fact (i 1)! = n! i > 0} i := i-1 {fact i! = n! i 0} By assignment again, we have {fact i (i 1)! = n! i > 0} fact := fact * i {fact (i 1)! = n! i > 0} This precondition is precisely P i > 0 COMP 2600 Hoare Logic II 4
5 Completing the proof P (fact i! = n! i 0) Apply the while-rule: {P} while (i>0)... {P i 0} By postcondition weakening, {P} while (i>0)... {fact = n!} Check that the initialisation establishes the invariant: {n 0} fact := 1; i := n {fact i! = n! i 0} COMP 2600 Hoare Logic II 5
6 Formally P (fact i! = n! i 0) 1. {1 n! = n! n 0} fact := 1 {fact n! = n! n 0} (Assignment) 2. {n 0} fact := 1 {fact n! = n! n 0} (1, Equivalence) 3. {fact n! = n! n 0} i := n {P} (Assignment) 4. {fact i (i 1)! = n! i > 0} fact := fact * i {fact (i 1)! = n! i > 0} 5. {P i > 0} fact := fact * i {fact (i 1)! = n! i > 0} (Assignment) (4, Equivalence) 6. {fact (i 1)! = n! i 1 0} i := i-1 {P} (Assignment) COMP 2600 Hoare Logic II 6
7 7. {fact (i 1)! = n! i > 0} i := i-1 {P} (6, Equivalence) 8. {P i > 0} fact := fact * i; i := i-1 {P} (5, 7, Sequencing) 9. {P} while (i>0)... {P i 0} (8, While) 10. {P} while (i>0)... {fact = n!} (9, Postcondition Weakening) 11. {n 0} Program {fact = n!} (2, 3, 10, Sequencing) COMP 2600 Hoare Logic II 7
8 Completeness of Hoare Logic All true Hoare triples can be proved (with expressive assertion language) However, we may not be able to verify a proof! Consider precondition strengthening rule: P s P w {P w } S {Q} {P s } S {Q} Not all arithmetic truths (P s P w ) can be proved (Gödel s incompleteness theorem) Hence, completeness is relative to access to arithmetic truths COMP 2600 Hoare Logic II 8
9 Weakest Precondition An assertion/condition maps program states to {true, false} (x > y)(σ) = true iff x > y in state σ Define assertion wp for all programs S and postconditions Q wp(s,q)(σ) = true iff for all states σ, (executing S in σ results in σ ) (Q(σ ) = true) With quantification, assertion language can express all wp(s, Q) Quantification required, e.g., to say x is a multiple of y : i. x = i y Formal proof uses Gödel s β function to encode sequence of numbers (representing states) of arbitrary length with small number of variables COMP 2600 Hoare Logic II 9
10 Properties of wp Definition: wp(s,q)(σ) = true iff for all states σ, (executing S in σ results in σ ) (Q(σ ) = true) {wp(s,q)} S {Q} wp is indeed a valid precondition If {P} S {Q} then P wp(s,q) wp is the weakest possible precondition ( denotes true or valid ) COMP 2600 Hoare Logic II 10
11 Proving Completeness of Hoare Logic Need only show {wp(s,q)} S {Q} for all S,Q If {P} S {Q} then P wp(s,q) So {P} S {Q} by precondition strengthening Proof by structural induction Assignment Sequencing Conditional While ( denotes provable ) COMP 2600 Hoare Logic II 11
12 Proof of Completeness: Assignment Need to show {wp(x:=e,q)} x:=e {Q} But wp(x:=e,q) = Q(e/x) Hence result follows by assignment rule COMP 2600 Hoare Logic II 12
13 Proof of Completeness: S 1 ; S 2 Need to show {wp(s 1 ; S 2,Q)} S 1 ; S 2 {Q} By induction, {wp(s 2,Q)} S 2 {Q} {wp(s 1,wp(S 2,Q))} S 1 {wp(s 2,Q)} By sequencing rule, {wp(s 1,wp(S 2,Q))} S 1 ; S 2 {Q} Finally, wp(s 1 ; S 2,Q) wp(s 1,wp(S 2,Q)), or wp(s 1 ; S 2,Q)(σ) wp(s 1,wp(S 2,Q))(σ) COMP 2600 Hoare Logic II 13
14 Proof of Completeness: if b then S 1 else S 2 Need to show {wp(if b then S 1 else S 2,Q)} if b then S 1 else S 2 {Q} By induction, {wp(s 1,Q)} S 1 {Q},{wp(S 2,Q)} S 2 {Q} Define P (b wp(s 1,Q)) ( b wp(s 2,Q)) By precondition equivalence and conditional rule, {P b} S 1 {Q},{P b} S 2 {Q} {P} if b then S 1 else S 2 {Q} Finally, by case analysis on b, wp(if b then S 1 else S 2,Q) P COMP 2600 Hoare Logic II 14
15 Proof of Completeness: while b do S Let P = wp(while b do S,Q) Lemma 1 b P Q P guarantees that Q holds in resulting state If b then while terminates immediately without modifying state Hence b (P Q) COMP 2600 Hoare Logic II 15
16 Proof of Completeness: while b do S Let P = wp(while b do S,Q) Lemma 2 b P wp(s,p), or equivalently {b P} S {P} Let σ be initial state where b P holds, σ the state after S terminates (trivial if S doesn t terminate). Wish to show P(σ ) = true If while doesn t terminate from σ, P(σ ) = true by definition of wp Let σ be state after while terminates Consider the run of while from σ: Q(σ ) = true Consider the run of while from σ : P(σ ) = true by definition of wp COMP 2600 Hoare Logic II 16
17 Proof of Completeness: while b do S Let P = wp(while b do S,Q) By induction, {wp(s,p)} S {P} By Lemma 2 (b P wp(s,p)) and precondition strengthening, {b P} S {P} By while-rule, Lemma 1 ( b P Q), and postcondition weakening, {P} while b do S {Q} COMP 2600 Hoare Logic II 17
18 Hoare logic expresses partial correctness {P} S {Q} means if P holds initially and S terminates then Q holds afterwards Does not guarantee that S terminates All Hoare triples are true where S does not terminate Hence no Hoare triple can express that S terminates Can express that S does not terminate though: {true} S {false} Provable if while condition is an invariant COMP 2600 Hoare Logic II 18
19 An Extension to Handle Total Correctness [P] S [Q] means if P holds initially then S terminates and Q holds afterwards Total correctness = partial correctness + termination To assert termination alone: [P] S [true] COMP 2600 Hoare Logic II 19
20 Rules for Total Correctness For deriving total correctness assertions [P] S [Q] all old rules continue to work, except one Assignment Precondition strengthening, postcondition weakening Sequencing Conditional While COMP 2600 Hoare Logic II 20
21 Rules for Total Correctness [Q(e)] x := e [Q(x)] (Assignment) Assumes evaluation of expression e always terminates Fine for our toy language Require expression to always return a number In general, depends on the language Can expression involve calls to functions, which may not terminate? Even absent while-loops, recursion could cause nontermination What if there s an error, e.g., division by zero? COMP 2600 Hoare Logic II 21
22 Rules for Total Correctness P s P w [P s ] S [Q] [P w ] S [Q] (Precondition Strengthening) [P] S [Q s ] [P] S [Q w ] Q s Q w (Postcondition Weakening) [P] S 1 [Q] [P] S 1 ; S 2 [R] [Q] S 2 [R] (Sequencing) [P b] S 1 [Q] [P b] S 2 [Q] [P] if b then S 1 else S 2 [Q] (Conditional) COMP 2600 Hoare Logic II 22
23 Termination of while [y > 0] while (y <= r) do r := r-y; q := q+1 [true] COMP 2600 Hoare Logic II 23
24 Termination of while [y > 0] while (y <= r) do r := r-y; q := q+1 [true] Observations: q := q+1 irrelevant y doesn t change, stays > 0 r strictly decreases on each iteration Hence y <= r will eventually be false COMP 2600 Hoare Logic II 24
25 Termination of while: General Condition [y > 0] while (y <= r) do r := r-y; q := q+1 [true] Find a variant, an expression E such that E stays 0 at beginning of each iteration E strictly decreases on each iteration What s a good E for this example? COMP 2600 Hoare Logic II 25
26 Total Correctness of while To show [P] while b do S [P b] in addition to showing partial correctness, find E such that E stays 0 at beginning of each iteration: P b E 0 E strictly decreases on each iteration [P b (E = n)] S [P (E < n)] (n is auxiliary variable not appearing elsewhere, used to remember initial value of E ) COMP 2600 Hoare Logic II 26
27 While-Rule for Total Correctness P b E 0 [P b (E = n)] S [P (E < n)] [P] while b do S [P b] (While) where n is an auxiliary variable not appearing elsewhere COMP 2600 Hoare Logic II 27
28 Using the Rule P b E 0 [P b (E = n)] S [P (E < n)] [P] while b do S [P b] (While) Prove [y > 0] while (y <= r) do {r := r-y; q := q+1} [true] 1. (y > 0) (y r) (r 0) (Math) 2. [(y > 0) (r < n)] q := q+1 [(y > 0) (r < n)] (Assignment) 3. [(y > 0) (r y < n)] r := r-y [(y > 0) (r < n)] (Assignment) 4. (y > 0) (y r) (r = n) (y > 0) (r y < n) (Math) 5. [(y > 0) (y r) (r = n)] r := r-y [(y > 0) (r < n)] (3, 4, Precondition Strengthening) 6. [(y > 0) (y r) (r = n)] r := r-y; q += q+1 [(y > 0) (r < n)] COMP 2600 Hoare Logic II 28
29 (5, 2, Sequencing) 7. [y > 0] while... [(y > 0) (y > r)] (1, 6, While) 8. [y > 0] while... [true] (7, Postcondition Weakening) COMP 2600 Hoare Logic II 29
30 Using the Rule P b E 0 [P b (E = n)] S [P (E < n)] [P] while b do S [P b] (While) [n 0] fact := 1; i := n; while (i >0) do fact := fact * i; i := i -1 [fact = n!] Same invariant P (fact i! = n! i 0) Variant E i (use m instead of n in while-rule) COMP 2600 Hoare Logic II 30
31 While-Rule for Total Correctness: Soundness P b E 0 [P b (E = n)] S [P (E < n)] [P] while b do S [P b] (While) Premises imply partial correctness of the while: [P b (E = n)] S [P (E < n)] [P b (E = n)] S [P] [P b] S [P] {P b} S {P} {P} while b do S {P b} (postcondition weakening) (n doesn t appear elsewhere) (total correctness implies partial correctness) (soundness of original while-rule) (All triples in the above chain of reasoning are semantic assertions) COMP 2600 Hoare Logic II 31
32 While-Rule for Total Correctness: Soundness P b E 0 [P b (E = n)] S [P (E < n)] [P] while b do S [P b] (While) Premises imply termination of the while: Show while b do S terminates from any state σ satisfying P, by induction on the value of E in σ If b(σ), done. Assume b(σ); have E(σ) 0 by left premise Base case (E(σ) = 0): Behavior of S (or the while) does not depend on value of n May as well assume n = 0 in σ Right premise implies P (E < 0) after one iteration This, together with left premise, implies b, hence termination of while COMP 2600 Hoare Logic II 32
33 While-Rule for Total Correctness: Soundness P b E 0 [P b (E = n)] S [P (E < n)] [P] while b do S [P b] (While) Premises imply termination of the while: Show while b do S terminates from any state σ satisfying P, by induction on the value of E in σ Inductive step: Hypothesis: while... terminates from any state σ satisfying P, if E(σ ) k Assume E(σ) = k + 1; may as well assume n = k + 1 in σ Right premise implies P (E k) after one iteration Hence while... terminates from that state, by induction hypothesis COMP 2600 Hoare Logic II 33
34 Total Correctness = Partial Correctness + Termination Do our rules agree with this equation? [P] S [Q] {P} S {Q} and [P] S [true]? [P] S [Q] [P] S [Q] (Soundness) {P} S {Q} (Semantics of Hoare Triples) {P} S {Q} (Completeness of Rules for Partial Correctness) [P] S [Q] [P] S [true] (Postcondition Weakening) COMP 2600 Hoare Logic II 34
35 Total Correctness = Partial Correctness + Termination Do our rules agree with this equation? {P} S {Q} and [P] S [true] [P] S [Q]? (You won t be asked to prove/disprove this) COMP 2600 Hoare Logic II 35
36 While-Rule for Total Correctness: Completeness P b E 0 [P b (E = n)] S [P (E < n)] [P] while b do S [P b] (While) Do we have a complete Hoare logic for total correctness? If [P] while... [Q], can we always find a suitable E to prove it? Values of variables in the while can change with no apparent pattern Can we always map them to a decreasing number with a simple expression E (using only +,, )? COMP 2600 Hoare Logic II 36
37 While-Rule for Total Correctness: Generalized Version P(z + 1) b P(0) b [P(z + 1)] S [P(z)] [ z. P(z)] while b do S [P(0)] where auxiliary variable z ranges over natural numbers (i.e., z 0) Think of z as remaining number of iterations before termination COMP 2600 Hoare Logic II 37
38 Using Generalized While-Rule P(z + 1) b P(0) b [P(z + 1)] S [P(z)] [ z. P(z)] while b do S [P(0)] where auxiliary variable z ranges over natural numbers (i.e., z 0) Prove [true] while (i > 0) do i := i-1 [true] P(z) (i = z) (i < 0 z = 0). Assuming z 0, we have P(z + 1) = (i = z + 1) (i < 0 z + 1 = 0) = (i = z + 1); this b P(0) = (i = 0) (i < 0 0 = 0) = (i 0); this is b [(i = z + 1) (i < 1 z = 0)] i := i-1 [P(z)] [P(z + 1)] i := i-1 [P(z)] (Assignment, Equiv.) (Precondition Strengthening) COMP 2600 Hoare Logic II 38
39 Using Generalized While-Rule P(z + 1) b P(0) b [P(z + 1)] S [P(z)] [ z. P(z)] while b do S [P(0)] where auxiliary variable z ranges over natural numbers (i.e., z 0) Prove [true] while (i > 0) do i := i-1 [true] P(z) (i = z) (i < 0 z = 0) Now apply generalized while-rule: [ z. (i = z) (i < 0 z = 0)] = [true] while (i > 0) do i := i-1 [(i = 0) (i < 0 0 = 0)] = [i 0] Final step by postcondition weakening COMP 2600 Hoare Logic II 39
40 Generalized While-Rule: Completeness P(z + 1) b P(0) b [P(z + 1)] S [P(z)] [ z. P(z)] while b do S [P(0)] where z ranges over natural numbers (i.e., z 0) Don t we have the same issue finding a decreasing expression? No, because we no longer need to express a function that computes z Given arbitrary numbers x 0,x 1,...,x k (representing sequence of states), there is a function β(m,n,i) such that β(m,n,i) = x i for all 0 i k Predicate β(m,n,z) = x implicitly turns arbitrary sequence of states (x ) into a decreasing number z Resulting Hoare logic is complete COMP 2600 Hoare Logic II 40
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 informationAxiomatic 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 informationDynamic 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 informationWeakest 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 informationTHE AUSTRALIAN NATIONAL UNIVERSITY Second Semester COMP2600/COMP6260 (Formal Methods for Software Engineering)
THE AUSTRALIAN NATIONAL UNIVERSITY Second Semester 2016 COMP2600/COMP6260 (Formal Methods for Software Engineering) Writing Period: 3 hours duration Study Period: 15 minutes duration Permitted Materials:
More informationHoare 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 informationFoundations of Computation
The Australian National University Semester 2, 2018 Research School of Computer Science Tutorial 6 Dirk Pattinson Foundations of Computation The tutorial contains a number of exercises designed for the
More informationLecture 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 informationAxiomatic 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 informationHoare 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 informationWhat 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 informationAxiomatic 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 informationMid-Semester Quiz Second Semester, 2012
THE AUSTRALIAN NATIONAL UNIVERSITY Mid-Semester Quiz Second Semester, 2012 COMP2600 (Formal Methods for Software Engineering) Writing Period: 1 hour duration Study Period: 10 minutes duration Permitted
More informationHoare 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 informationHoare 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 informationAxiomatic 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 informationLast 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 informationAxiomatic 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 informationCS558 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 informationProgram 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 informationClassical 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 informationProgram 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 informationCSE 331 Winter 2018 Reasoning About Code I
CSE 331 Winter 2018 Reasoning About Code I Notes by Krysta Yousoufian Original lectures by Hal Perkins Additional contributions from Michael Ernst, David Notkin, and Dan Grossman These notes cover most
More informationAxiomatic 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 informationProof 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 informationTHE AUSTRALIAN NATIONAL UNIVERSITY Second Semester COMP2600 (Formal Methods for Software Engineering)
THE AUSTRALIAN NATIONAL UNIVERSITY Second Semester 2012 COMP2600 (Formal Methods for Software Engineering) Writing Period: 3 hours duration Study Period: 15 minutes duration Permitted Materials: One A4
More informationSoundness 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 informationIn 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 informationCSC 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 informationProgramming 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 informationThe 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 informationHoare 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 informationProof 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 informationProgramming 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 informationTHE AUSTRALIAN NATIONAL UNIVERSITY Second Semester COMP2600 (Formal Methods in Software Engineering)
THE AUSTRALIAN NATIONAL UNIVERSITY Second Semester 2007 COMP2600 (Formal Methods in Software Engineering) Writing Period: 3 hours duration Study Period: 15 minutes duration Permitted Materials: None Answer
More informationBilateral 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 informationSpring 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 informationIntroduction 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 informationPropositional 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 informationTHE AUSTRALIAN NATIONAL UNIVERSITY Second Semester COMP2600 (Formal Methods for Software Engineering)
THE AUSTRALIAN NATIONAL UNIVERSITY Second Semester 2010 COMP2600 (Formal Methods for Software Engineering) Writing Period: 3 hours duration Study Period: 15 minutes duration Permitted Materials: One A4
More informationFormal Reasoning CSE 331. Lecture 2 Formal Reasoning. Announcements. Formalization and Reasoning. Software Design and Implementation
CSE 331 Software Design and Implementation Lecture 2 Formal Reasoning Announcements Homework 0 due Friday at 5 PM Heads up: no late days for this one! Homework 1 due Wednesday at 11 PM Using program logic
More informationProgram 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 informationSoftware 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 informationDeductive 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 informationA 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 informationDesign 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 informationDeterministic 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 informationProgram 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 informationSoftwaretechnik. 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 informationSoftwaretechnik. 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 informationSolutions 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 informationSpring 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 informationLoop 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 informationGödel s Incompleteness Theorem. Overview. Computability and Logic
Gödel s Incompleteness Theorem Overview Computability and Logic Recap Remember what we set out to do in this course: Trying to find a systematic method (algorithm, procedure) which we can use to decide,
More informationThe L Machines are very high-level, in two senses:
What is a Computer? State of the machine. CMPSCI 630: Programming Languages An Abstract Machine for Control Spring 2009 (with thanks to Robert Harper) Internal registers, memory, etc. Initial and final
More informationFloyd-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 informationStrength; 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 informationReasoning 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 informationGödel s Incompleteness Theorem. Overview. Computability and Logic
Gödel s Incompleteness Theorem Overview Computability and Logic Recap Remember what we set out to do in this course: Trying to find a systematic method (algorithm, procedure) which we can use to decide,
More informationProofs 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 informationLogic. 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 informationLogic. 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 informationCOP4020 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 informationIntroduction to Axiomatic Semantics
Introduction to Axiomatic Semantics Meeting 9, CSCI 5535, Spring 2009 Announcements Homework 3 is out, due Mon Feb 16 No domain theory! Homework 1 is graded Feedback attached 14.2 (mean), 13 (median),
More informationUnifying 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 informationVerification and Validation
2010-2011 Cycle Ingénieur 2 ème année Département Informatique Verification and Validation Part IV : Proof-based Verification (III) Burkhart Wolff Département Informatique Université Paris-Sud / Orsay
More informationDecision Procedures. Jochen Hoenicke. Software Engineering Albert-Ludwigs-University Freiburg. Winter Term 2016/17
Decision Procedures Jochen Hoenicke Software Engineering Albert-Ludwigs-University Freiburg Winter Term 2016/17 Jochen Hoenicke (Software Engineering) Decision Procedures Winter Term 2016/17 1 / 436 Program
More informationLearning 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 informationCSE 331 Software Design & Implementation
CSE 331 Software Design & Implementation Kevin Zatloukal Summer 2017 Lecture 2 Reasoning About Code With Logic (Based on slides by Mike Ernst, Dan Grossman, David Notkin, Hal Perkins, Zach Tatlock) Recall
More informationFormal 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 informationLecture Notes on Invariants for Arbitrary Loops
15-414: Bug Catching: Automated Program Verification Lecture Notes on Invariants for Arbitrary Loops Matt Fredrikson Ruben Martins Carnegie Mellon University Lecture 5 1 Introduction The previous lecture
More informationSemantics and Verification of Software
Semantics and Verification of Software Thomas Noll Software Modeling and Verification Group RWTH Aachen University http://moves.rwth-aachen.de/teaching/ss-15/sv-sw/ The Denotational Approach Denotational
More informationAxiomatic 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 informationWhat are the recursion theoretic properties of a set of axioms? Understanding a paper by William Craig Armando B. Matos
What are the recursion theoretic properties of a set of axioms? Understanding a paper by William Craig Armando B. Matos armandobcm@yahoo.com February 5, 2014 Abstract This note is for personal use. It
More informationCSE 331 Winter 2018 Homework 1
Directions: - Due Wednesday, January 10 by 11 pm. - Turn in your work online using gradescope. You should turn in a single pdf file. You can have more than one answer per page, but please try to avoid
More informationAxiomatic 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 informationLecture 17: Floyd-Hoare Logic for Partial Correctness
Lecture 17: Floyd-Hoare Logic for Partial Correctness Aims: To look at the following inference rules Page 1 of 9 sequence; assignment and consequence. 17.1. The Deduction System for Partial Correctness
More informationMarie 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 informationCOMP2111 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 informationCSE20: Discrete Mathematics
Spring 2018 Summary Today: Induction, Program Correctness Reading: Chap. 5 Division Theorem Theorem: For every integer a and positive integer d 1, there exist integers q, r such that a = qd + r and 0 r
More informationarxiv: 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 informationIntroduction to Metalogic
Philosophy 135 Spring 2008 Tony Martin Introduction to Metalogic 1 The semantics of sentential logic. The language L of sentential logic. Symbols of L: Remarks: (i) sentence letters p 0, p 1, p 2,... (ii)
More informationControl 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 information07 Equational Logic and Algebraic Reasoning
CAS 701 Fall 2004 07 Equational Logic and Algebraic Reasoning Instructor: W. M. Farmer Revised: 17 November 2004 1 What is Equational Logic? Equational logic is first-order logic restricted to languages
More informationFirst 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 informationFormal 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 informationProbabilistic 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 informationHoare 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 informationEDA045F: Program Analysis LECTURE 10: TYPES 1. Christoph Reichenbach
EDA045F: Program Analysis LECTURE 10: TYPES 1 Christoph Reichenbach In the last lecture... Performance Counters Challenges in Dynamic Performance Analysis Taint Analysis Binary Instrumentation 2 / 44 Types
More informationAxiomatic Verification II
Axiomatic Verification II Software Testing and Verification Lecture Notes 18 Prepared by Stephen M. Thebaut, Ph.D. University of Florida Axiomatic Verification II Reasoning about iteration (while loops)
More informationProving 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 information1. Propositional Calculus
1. Propositional Calculus Some notes for Math 601, Fall 2010 based on Elliott Mendelson, Introduction to Mathematical Logic, Fifth edition, 2010, Chapman & Hall. 2. Syntax ( grammar ). 1.1, p. 1. Given:
More informationMathematical Induction. How does discrete math help us. How does discrete math help (CS160)? How does discrete math help (CS161)?
How does discrete math help us Helps create a solution (program) Helps analyze a program How does discrete math help (CS160)? Helps create a solution (program) q Logic helps you understand conditionals
More informationCS 336. We use the principle of inclusion and exclusion. Let B. = {five digit decimal numbers ending with a 5}, and
CS 336 1. The important issue is the logic you used to arrive at your answer. 2. Use extra paper to determine your solutions then neatly transcribe them onto these sheets. 3. Do not submit the scratch
More information1. Propositional Calculus
1. Propositional Calculus Some notes for Math 601, Fall 2010 based on Elliott Mendelson, Introduction to Mathematical Logic, Fifth edition, 2010, Chapman & Hall. 2. Syntax ( grammar ). 1.1, p. 1. Given:
More informationLecture Notes: Program Analysis Correctness
Lecture Notes: Program Analysis Correctness 15-819O: Program Analysis Jonathan Aldrich jonathan.aldrich@cs.cmu.edu Lecture 5 1 Termination As we think about the correctness of program analysis, let us
More informationTute 10. Liam O'Connor. May 23, 2017
Tute 10 Liam O'Connor May 23, 2017 proc Search(value g : G, value s : V g, value k : K, result v : T, result f : B) Where a graph g : G is dened as a 4-tuple (V, Γ, κ, λ) containing a set of vertices V,
More informationA Logic for Information Flow Analysis with an Application to Forward Slicing of Simple Imperative Programs
A Logic for Information Flow Analysis with an Application to Forward Slicing of Simple Imperative Programs Torben Amtoft and Anindya Banerjee a,1,2 a Department of Computing and Information Sciences Kansas
More informationCS156: 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 informationPredicate 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