Software Engineering

Size: px
Start display at page:

Download "Software Engineering"

Transcription

1 Software Engineering Lecture 07: Design by Contract Peter Thiemann University of Freiburg, Germany

2 Table of Contents Design by Contract Contracts for Procedural Programs Contracts for Object-Oriented Programs Contract Monitoring Verification of Contracts Peter Thiemann (Univ. Freiburg) Software Engineering / 62

3 Contracts for Procedural Programs Contracts for Procedural Programs Peter Thiemann (Univ. Freiburg) Software Engineering / 62

4 Contracts for Procedural Programs Underlying Idea Transfer the notion of contract between business partners to software engineering. What is a contract? A binding agreement that explicitly states the obligations and the benefits of each partner. Peter Thiemann (Univ. Freiburg) Software Engineering / 62

5 Contracts for Procedural Programs Example: Contract between Builder and Landowner Obligations Landowner Provide 5 acres of land; pay for building if completed in time Builder Build house on provided land in less than six month Benefits Get building in less than six months No need to do anything if provided land is smaller than 5 acres; Receive payment if house finished in time Peter Thiemann (Univ. Freiburg) Software Engineering / 62

6 Contracts for Procedural Programs Who are the contract partners in SE? Partners can be modules/procedures, objects/methods, components/operations,... In terms of software architecture, the partners are the components and each connector may carry a contract. Peter Thiemann (Univ. Freiburg) Software Engineering / 62

7 Contracts for Procedural Programs Contracts for Procedural Programs Goal: Specification of imperative procedures Approach: give assertions about the procedure Precondition must be true on entry ensured by caller of procedure Postcondition must be true on exit ensured by procedure if it terminates Precondition(State) Postcondition(procedure(State)) Notation: {Precondition} procedure {Postcondition} Assertions stated in first-order predicate logic Peter Thiemann (Univ. Freiburg) Software Engineering / 62

8 Contracts for Procedural Programs Example Consider the following procedure: a an integer square root of a / int root (int a) { int i = 0; int k = 1; int sum = 1; while (sum <= a) { k = k+2; i = i+1; sum = sum+k; } return i; } Peter Thiemann (Univ. Freiburg) Software Engineering / 62

9 Contracts for Procedural Programs Specification of root types guaranteed by compiler: a integer and root integer (the result) 1. root as a partial function Precondition: a 0 Postcondition: root root a < (root + 1) (root + 1) 2. root as a total function Precondition: true Postcondition: (a 0 root root a < (root + 1) (root + 1)) (a < 0 root = 0) Peter Thiemann (Univ. Freiburg) Software Engineering / 62

10 Contracts for Procedural Programs Weakness and Strength Goal: find weakest precondition a precondition that is implied by all other preconditions highest demand on procedure largest domain of procedure (Q: what if precondition = false?) find strongest postcondition a postcondition that implies all other postconditions smallest range of procedure (Q: what if postcondition = true?) Met by root as a total function : true is weakest possible precondition defensive programming Peter Thiemann (Univ. Freiburg) Software Engineering / 62

11 Contracts for Procedural Programs Example (Weakness and Strength) Consider root as a function over integers Precondition: true Postcondition: (a 0 root root a < (root + 1) (root + 1)) (a < 0 root = 0) true is the weakest precondition The postcondition can be strengthened to (root 0) (a 0 root root a < (root + 1) (root + 1)) (a < 0 root = 0) Peter Thiemann (Univ. Freiburg) Software Engineering / 62

12 Contracts for Procedural Programs An Example Insert an element in a table of fixed size class TABLE<T> { int capacity; // size of table int count; // number of elements in table T get (String key) {...} void put (T element, String key); } Precondition: table is not full count < capacity Postcondition: new element in table, count updated count capacity get(key) = element count = old count + 1 Peter Thiemann (Univ. Freiburg) Software Engineering / 62

13 Contracts for Procedural Programs Caller Procedure Obligations Call put only on non-full table Insert element in table so that it may be retrieved through key Benefits Get modified table in which element is associated with key No need to deal with the case where table is full before insertion Peter Thiemann (Univ. Freiburg) Software Engineering / 62

14 Contracts for Object-Oriented Programs Contracts for Object-Oriented Programs Peter Thiemann (Univ. Freiburg) Software Engineering / 62

15 Contracts for Object-Oriented Programs Contracts for Object-Oriented Programs Contracts for methods have additional features local state receiving object s state must be specified inheritance and dynamic method dispatch receiving object s type may be different than statically expected; method may be overridden Peter Thiemann (Univ. Freiburg) Software Engineering / 62

16 Contracts for Object-Oriented Programs Local State: Class Invariant class invariant INV is predicate that holds for all objects of the class must be established by all constructors must be maintained by all public methods Peter Thiemann (Univ. Freiburg) Software Engineering / 62

17 Contracts for Object-Oriented Programs Pre- and Postconditions for Methods constructor methods c {Pre c } c {INV } visible methods m {Pre m INV } m {Post m INV } Peter Thiemann (Univ. Freiburg) Software Engineering / 62

18 Contracts for Object-Oriented Programs Table example revisited count and capacity are instance variables of class TABLE INV TABLE is count capacity specification of void put (T element, String key) Precondition: count < capacity Postcondition: get(key) = element count = old count + 1 Peter Thiemann (Univ. Freiburg) Software Engineering / 62

19 Contracts for Object-Oriented Programs Inheritance and Dynamic Binding Subclass may override a method definition Effect on specification: Subclass may have different invariant Redefined methods may have different pre- and postconditions raise different exceptions method specialization Relation to invariant and pre-, postconditions in base class? Guideline: No surprises requirement (Wing, FMOODS 1997) Properties that users rely on to hold of an object of type T should hold even if the object is actually a member of a subtype S of T. Peter Thiemann (Univ. Freiburg) Software Engineering / 62

20 Contracts for Object-Oriented Programs Invariant of a Subclass Suppose class MYTABLE extends TABLE... each property expected of a TABLE object should also be granted by a MYTABLE object if o has type MYTABLE then INV TABLE must hold for o INV MYTABLE INV TABLE Example: MYTABLE might be a hash table with invariant INV MYTABLE count capacity/3 Peter Thiemann (Univ. Freiburg) Software Engineering / 62

21 Contracts for Object-Oriented Programs Method Specialization If MYTABLE redefines put then... the precondition in the subclass must be weaker and the postcondition in the subclass must be stronger than in the superclass because in TABLE personnel = new MYTABLE (150);... personnel.put (new Terminator (3), Arnie ); the caller only guarantees Pre put,table and expects Post put,table Peter Thiemann (Univ. Freiburg) Software Engineering / 62

22 Contracts for Object-Oriented Programs Requirements for Method Specialization Suppose class T defines method m with assertions Pre T,m and Post T,m throwing exceptions Exc T,m. If class S extends class T and redefines m then the redefinition is a sound method specialization if Pre T,m Pre S,m and Post S,m Post T,m and Exc S,m Exc T,m each exception thrown by S.m may also be thrown by T.m Peter Thiemann (Univ. Freiburg) Software Engineering / 62

23 Contracts for Object-Oriented Programs Example: MYTABLE.put Pre MYTABLE,put count < capacity/3 not a sound method specialization because it is not implied by count < capacity. MYTABLE may automatically resize the table, so that Pre MYTABLE,put true is a sound method specialization because count < capacity true! Suppose MYTABLE adds a new instance variable T lastinserted that holds the last value inserted into the table. Post MYTABLE,put item(key) = element count = old count + 1 lastinserted = element is a sound method specialization because Post MYTABLE,put Post TABLE,put Peter Thiemann (Univ. Freiburg) Software Engineering / 62

24 Contracts for Object-Oriented Programs Interlude: Method Specialization since Java 5 Overriding methods in Java 5 only allows specialization of the result type. (It can be replaced by a subtype). The parameter types muss stay unchanged (why?) Example : Assume B extends A class Original { A m () { return new A(); } } class Specialization extends Original { B m () { // overrides method Original.m() return new B(); } } Peter Thiemann (Univ. Freiburg) Software Engineering / 62

25 Contracts for Object-Oriented Programs Interlude: NO Specialization Method specialization interferes with overloading in Java Class Specialization has two different methods Example : Assume B extends A class Original { void m (B x) { return; } } class Specialization extends Original { void m (A x) { // does NOT override method Original.m() return; } } Peter Thiemann (Univ. Freiburg) Software Engineering / 62

26 Contract Monitoring Contract Monitoring Peter Thiemann (Univ. Freiburg) Software Engineering / 62

27 Contract Monitoring Contract Monitoring What happens if a system s execution violates an assertion at run time? A violating execution runs outside the system s specification. The system s reaction may be arbitrary crash continue Peter Thiemann (Univ. Freiburg) Software Engineering / 62

28 Contract Monitoring Contract Monitoring What happens if a system s execution violates an assertion at run time? A violating execution runs outside the system s specification. The system s reaction may be arbitrary crash continue Contract Monitoring evaluates assertions at run time raises an exception indicating any violation assign blame for the violation Peter Thiemann (Univ. Freiburg) Software Engineering / 62

29 Contract Monitoring Contract Monitoring What happens if a system s execution violates an assertion at run time? A violating execution runs outside the system s specification. The system s reaction may be arbitrary crash continue Contract Monitoring evaluates assertions at run time raises an exception indicating any violation assign blame for the violation Why monitor? Debugging (with different levels of monitoring) Software fault tolerance (e.g., α and β releases) Peter Thiemann (Univ. Freiburg) Software Engineering / 62

30 Contract Monitoring What can go wrong precondition: evaluate assertion on entry identifies problem in the caller postcondition: evaluate assertion on exit identifies problem in the callee invariant: evaluate assertion on entry and exit problem in the callee s class hierarchy: unsound method specialization in class S need to check (for all superclasses T of S) Pre T,m Pre S,m on entry and Post S,m Post T,m on exit how? Peter Thiemann (Univ. Freiburg) Software Engineering / 62

31 Contract Monitoring Hierarchy Checking Suppose class S extends T and overrides a method m. Let T x = new S() and consider x.m() on entry if Pre T,m holds, then Pre S,m must hold, too PreS,m must hold If the precondition of S is not fulfilled, but the one of T is, then this is a wrong method specialization. on exit Post S,m must hold if PostS,m holds, then Post T,m must hold, too In general, with more than two classes: Cascade of implications between S and T must be checked. All intermediate pre- and postconditions must be checked. Peter Thiemann (Univ. Freiburg) Software Engineering / 62

32 Contract Monitoring Examples interface IConsole { getmaxsize > 0 } int { s.length () < this.getmaxsize() } void display (String s); } class Console implements IConsole { getmaxsize > 0 } int getmaxsize () {... { s.length () < this.getmaxsize() } void display (String s) {... } Peter Thiemann (Univ. Freiburg) Software Engineering / 62

33 Contract Monitoring A Good Extension class RunningConsole extends Console { true } void display (String s) {... super.display(string. substring (s,...,... + getmaxsize()))... } } Peter Thiemann (Univ. Freiburg) Software Engineering / 62

34 Contract Monitoring A Bad Extension class PrefixedConsole extends Console { String getprefix() { return >> ; { s.length() < this.getmaxsize() this.getprefix().length() } void display (String s) { super.display (this.getprefix() + s); } } caller may only guarantee IConsole s precondition Console.display can be called with argument that is too long blame the programmer of PrefixedConsole! Peter Thiemann (Univ. Freiburg) Software Engineering / 62

35 Contract Monitoring Properties of Monitoring Assertions can be arbitrary side effect-free boolean expressions Instrumentation for monitoring can be generated from the assertions Monitoring can only prove the presence of violations, not their absence Absence of violations can only be guaranteed by formal verification Peter Thiemann (Univ. Freiburg) Software Engineering / 62

36 Verification of Contracts Verification of Contracts Peter Thiemann (Univ. Freiburg) Software Engineering / 62

37 Verification of Contracts Verification of Contracts Given: Specification of imperative procedure by Precondition and Postcondition Goal: Formal proof for Precondition(State) Postcondition(procedure(State)) if procedure(state) terminates Method: Hoare Logic, i.e., a proof system for Hoare triples of the form {Precondition} procedure {Postcondition} named after C.A.R. Hoare, inventor of Quicksort, CSP, and many other here: method bodies, no recursion, no pointers (extensions exist) Peter Thiemann (Univ. Freiburg) Software Engineering / 62

38 Verification of Contracts Syntax of While A small language to illustrate verification E ::= c x E + E... expressions B, P, Q ::= B P Q P Q boolean expressions E = E E E... C, D ::= skip no operation x E assignment C;D sequence if B then C else D conditional while B do C iteration H ::= {P}C{Q} Hoare triples (boolean) expressions are free of side effects Peter Thiemann (Univ. Freiburg) Software Engineering / 62

39 Verification of Contracts Proof Rules for Hoare Triples It is possible, but tedious, to prove that {P} C {Q} holds directly from the definition: If P(σ) and σ = S C σ is terminating, then P(σ ) holds Instead: define axioms and inferences rules Construct a derivation to prove the triple Choice of axioms and rules guided by structure of C Peter Thiemann (Univ. Freiburg) Software Engineering / 62

40 Verification of Contracts Skip Axiom {P} skip {P} Peter Thiemann (Univ. Freiburg) Software Engineering / 62

41 Verification of Contracts Assignment Axiom {P[x E]} x E {P} Examples: {1 == 1} x 1 {x == 1} {odd(1)} x 1 {odd(x)} {x == 2 y + 1} y 2 y {x == y + 1} Peter Thiemann (Univ. Freiburg) Software Engineering / 62

42 Verification of Contracts Sequence Rule Example: {P} C {R} {R} D {Q} {P} C;D {Q} {x == 2 y + 1} y 2 y {x == y + 1} {x == y + 1} y y + 1 {x == y} {x == 2 y + 1} y 2 y; y y + 1 {x == y} Peter Thiemann (Univ. Freiburg) Software Engineering / 62

43 Verification of Contracts Conditional Rule {P B} C {Q} {P B} D {Q} {P} if B then C else D {Q} Peter Thiemann (Univ. Freiburg) Software Engineering / 62

44 Verification of Contracts Conditional Rule Issues Examples: {P x < 0} z x {z == x } {P x 0} z x {z == x } {P} if x < 0 then z x else z x {z == x } incomplete! precondition for z x should be (z == x )[z x] x == x need logical rules Peter Thiemann (Univ. Freiburg) Software Engineering / 62

45 Verification of Contracts Logical Rules weaken precondition strengthen postcondition P P {P} C {Q} {P } C {Q} {P} C {Q} Q Q {P} C {Q } Example needs strengthening: P x < 0 x == x holds for all P similarly: P x 0 x == x Peter Thiemann (Univ. Freiburg) Software Engineering / 62

46 Verification of Contracts Completed example: D 1 = x < 0 x == x { x == x } z x {z == x } {x < 0} z x {z == x } D 2 = x 0 x == x {x == x } z x {z == x } {x 0} z x {z == x } D 1 D 2 {x < 0} z x {z == x } {x 0} z x {z == x } {true} if x < 0 then z x else z x {z == x } Peter Thiemann (Univ. Freiburg) Software Engineering / 62

47 Verification of Contracts While Rule {P B} C {P} {P} while B do C {P B} P is loop invariant Example: try to prove { a>=0 /\ i==0 /\ k==1 /\ sum==1 } while sum <= a do k <- k+2; i <- i+1; sum <- sum+k { i*i <= a /\ a < (i+1)*(i+1) } while rule not directly applicable... Peter Thiemann (Univ. Freiburg) Software Engineering / 62

48 Verification of Contracts While Rule Step 1: Find the loop invariant a>=0 /\ i==0 /\ k==1 /\ sum==1 => i*i<=a /\ i>=0 /\ k==2*i+1 /\ sum==(i+1)*(i+1) P i i a i 0 k == 2 i + 1 sum == (i + 1) (i + 1) holds on entry to the loop To prove that P is an invariant, requires to prove that {P sum a} k k + 2; i i + 1; sum sum + k {P} It follows by the sequence rule and weakening: Peter Thiemann (Univ. Freiburg) Software Engineering / 62

49 Verification of Contracts Proof of loop invariance { i*i<=a i>=0 k==2*i+1 sum==(i+1)*(i+1) sum<=a } { i>=0 k+2==2+2*i+1 sum==(i+1)*(i+1) sum<=a } k <- k+2 { i>=0 k==2+2*i+1 sum==(i+1)*(i+1) sum<=a } { i+1>=1 k==2*(i+1)+1 sum==(i+1)*(i+1) sum<=a } i <- i+1 { i>=1 k==2*i+1 sum==i*i sum<=a } { i*i<=a i>=1 k==2*i+1 sum+k==i*i+k sum+k<=a+k } sum <- sum+k { i*i<=a i>=1 k==2*i+1 sum==i*i+k sum<=a+k } { i*i<=a i>=1 k==2*i+1 sum==i*i+2*i+1 sum<=a+k } { i*i<=a i>=1 k==2*i+1 sum==(i+1)*(i+1) sum<=a+k } { i*i<=a i>=0 k==2*i+1 sum==(i+1)*(i+1) } Peter Thiemann (Univ. Freiburg) Software Engineering / 62

50 Verification of Contracts Step 2: Apply the while rule {P sum a} k k + 2; i i + 1; sum sum + k {P} {P} while sum a do k k + 2; i i + 1; sum sum + k {P sum > a} Now, P sum > a is { i*i<=a /\ i>=0 /\ k==2*i+1 /\ sum==(i+1)*(i+1) /\ sum>a } implies { i*i<=a /\ a<(i+1)*(i+1) } Peter Thiemann (Univ. Freiburg) Software Engineering / 62

51 Verification of Contracts Soundness of the Rules Intuitively, the proof rules are ok. But are they sound? Is there a definition from which {P} C {Q} can be proved directly? Answer: Yes! Each rule can be proved correct from this definition. First step: define the meaning of expressions and statements Peter Thiemann (Univ. Freiburg) Software Engineering / 62

52 Verification of Contracts Semantics Domains and Types BValue = true false IValue = σ State = Variable Value E : Expression State IValue B : BoolExpression State BValue S : State State State := State { } result indicates non-termination Peter Thiemann (Univ. Freiburg) Software Engineering / 62

53 Verification of Contracts Semantics Expressions E c σ = c E x σ = σ(x) E E+F σ = E E σ + E F σ... B E = F σ = E E σ = E F σ B B σ = B B σ... Peter Thiemann (Univ. Freiburg) Software Engineering / 62

54 Verification of Contracts Semantics Statements S C = S skip σ = σ S x E σ = σ[x E E σ] S C;D σ = S D (S C σ) S if B then C else D σ = B B σ = true S C σ, S D σ S while B do C σ = F (σ) where F ( ) = F (σ) = B B σ = true F (S C σ), σ McCarthy conditional: b e 1, e 2 Peter Thiemann (Univ. Freiburg) Software Engineering / 62

55 Verification of Contracts Proving a Hoare triple Theorem The Hoare triple {P} C {Q} holds according to the rules of Hoare calculus if ( σ State) P(σ) (Q(S C σ) S C σ = ) (partial correctness) Alternative readings predicates as sets of states: P, Q State {P} C {Q} S C P Q predicates as boolean expressions: B P σ = true (B Q (S C σ) = true S C σ = ) Proof By induction on the derivation of {P} C {Q}: For each Hoare rule, if the above hypothesis holds for the assumptions, then it holds for the conclusion. Peter Thiemann (Univ. Freiburg) Software Engineering / 62

56 Verification of Contracts Skip Axiom Correctness {P} skip {P} Correctness S skip σ = σ Assume B P σ = true. Then B P (S skip σ) = B P σ = true Peter Thiemann (Univ. Freiburg) Software Engineering / 62

57 Verification of Contracts Assignment Axiom Correctness {P[x E]} x E {P} Semantics: S x E σ = σ[x E E σ] Under assumption B P[x E] σ = true show that (B P (S x E σ) = true S x E σ = ) Apply definition of semantics to rhs; show that B P[x E] σ = true implies (B P (σ[x E E σ]) = true S x E σ = ) Requires induction on boolean expression P: Peter Thiemann (Univ. Freiburg) Software Engineering / 62

58 Verification of Contracts Assignment Axiom Correctness II Prove B P[x E] σ = B P (σ[x E E σ]) by induction on P. Case P Q: B Q[x E] σ def = B Q[x E] σ IH = B Q (σ[x E E σ]) def = B Q (σ[x E E σ]) Cases P Q Q and P Q Q analogously. Case P E = E : B (E = E )[x E] σ def = (E E [x E] σ = E E [x E] σ) Need another lemma: E E [x E] σ = E E σ[x E E σ] = (E E σ[x E E σ] = E E σ[x E E σ]) def = E E = E σ[x E E σ] Case P E E etc: analogously. Peter Thiemann (Univ. Freiburg) Software Engineering / 62

59 Verification of Contracts Assignment Axiom Correctness III Remains to show that E E [x E] σ = E E σ[x E E σ] by induction on E. Case E x: E x[x E] σ = E E σ = E x σ[x E E σ] Case E y, y x: E y[x E] σ = E y σ = σ(y) = σ[x E E σ](y) = E y σ[x E E σ] Case E E : Immediate by induction. E E [x E] σ def = E E [x E] σ IH = E E σ[x E E σ] def = E E σ[x E E σ] Case E E + E etc: analogously. Peter Thiemann (Univ. Freiburg) Software Engineering / 62

60 Verification of Contracts Sequence Rule Correctness Proof {P} C {R} {R} D {Q} {P} C;D {Q} Assume B P σ = true Show S C; D σ = or B Q (S C; D σ) = true Induction on {P} C {R} yields B R (S C σ) = true S C σ = If S C σ = then the rule is correct because S C;D σ =. Otherwise: induction on {R} C {Q} yields B Q (S D (S C σ)) = true S D (S C σ) = Recall that S D (S C σ) def = S C;D σ If S D (S C σ) = then the rule is correct because S C;D σ =. Otherwise: B Q (S C;D σ) = true QED Peter Thiemann (Univ. Freiburg) Software Engineering / 62

61 Verification of Contracts Conditional Rule Correctness {P B} C {Q} {P B} D {Q} {P} if B then C else D {Q} Correctness Show: σ P implies S if B then C else D Q { } Exercise Peter Thiemann (Univ. Freiburg) Software Engineering / 62

62 Verification of Contracts Logical Rules Correctness weaken precondition strengthen postcondition Correctness P P iff P P (as set of states) P P {P} C {Q} {P } C {Q} {P} C {Q} Q Q {P} C {Q } Peter Thiemann (Univ. Freiburg) Software Engineering / 62

63 Verification of Contracts While-Rule Correctness {P B} C {P} {P} while B do C {P B} Recall the semantics of while: S while B do C σ = F (σ) where F ( ) = and F (σ) = B B σ = true F (S C σ), σ It is sufficient to show (fixpoint induction): If ( σ P), F (σ) P B { } then ( σ P), B B σ = true F (S C σ), σ P B { } Case B B σ = true: By induction on {P B} C {P}, either S C σ = (then F (S C σ) = F ( ) = completes the proof), or S C σ P (then F (S C σ) P B { } completes the proof) Case B B σ = false: Then σ P B. QED Peter Thiemann (Univ. Freiburg) Software Engineering / 62

64 Verification of Contracts Properties of Formal Verification requires more restrictions on assertions (e.g., use a certain logic) than monitoring full compliance of code with specification can be guaranteed scalability and expressivity are challenging research topics: full automation manageable for small/medium examples large examples require manual interaction real programs use dynamic datastructures (pointers, objects) and concurrency Peter Thiemann (Univ. Freiburg) Software Engineering / 62

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

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

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

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 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

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. 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

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

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

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

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

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

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

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

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

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

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 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

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

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

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

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

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

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

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

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

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

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

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

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 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

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

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

Formal Reasoning CSE 331. Lecture 2 Formal Reasoning. Announcements. Formalization and Reasoning. Software Design and Implementation

Formal 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 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

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

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

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

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

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

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

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

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

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

THE AUSTRALIAN NATIONAL UNIVERSITY Second Semester COMP2600 (Formal Methods for Software Engineering)

THE 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 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

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

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

Foundations of Computation

Foundations 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 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

Semantics and Verification of Software

Semantics 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 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

CSE 331 Software Design & Implementation

CSE 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 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

CSE 331 Winter 2018 Reasoning About Code I

CSE 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 information

Static Program Analysis

Static Program Analysis Static Program Analysis Lecture 16: Abstract Interpretation VI (Counterexample-Guided Abstraction Refinement) Thomas Noll Lehrstuhl für Informatik 2 (Software Modeling and Verification) noll@cs.rwth-aachen.de

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

Erasable Contracts. Abstract. 1. Introduction. Harvard University {jchinlee,

Erasable Contracts. Abstract. 1. Introduction. Harvard University {jchinlee, Erasable Contracts Jao-ke Chin-Lee Louis Li Harvard University {jchinlee, louisli}@college.harvard.edu Abstract Contract programming is a design approach that allows programmers to design formal specifications

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

AN INTRODUCTION TO SEPARATION LOGIC. 2. Assertions

AN INTRODUCTION TO SEPARATION LOGIC. 2. Assertions AN INTRODUCTION TO SEPARATION LOGIC 2. Assertions John C. Reynolds Carnegie Mellon University January 7, 2011 c 2011 John C. Reynolds Pure Assertions An assertion p is pure iff, for all stores s and all

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

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

Mid-Semester Quiz Second Semester, 2012

Mid-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 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

Predicate Logic. x. x + 0 = x. Predicate logic over integer expressions: a language of logical assertions, for example. Why discuss predicate logic?

Predicate Logic. x. x + 0 = x. Predicate logic over integer expressions: a language of logical assertions, for example. Why discuss predicate logic? Predicate Logic Predicate logic over integer expressions: a language of logical assertions, for example x. x + 0 = x Why discuss predicate logic? It is an example of a simple language It has simple denotational

More information

THE AUSTRALIAN NATIONAL UNIVERSITY Second Semester COMP2600/COMP6260 (Formal Methods for Software Engineering)

THE 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 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

Predicate Logic. Xinyu Feng 11/20/2013. University of Science and Technology of China (USTC)

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

More information

Simply Typed Lambda Calculus

Simply Typed Lambda Calculus Simply Typed Lambda Calculus Language (ver1) Lambda calculus with boolean values t ::= x variable x : T.t abstraction tt application true false boolean values if ttt conditional expression Values v ::=

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

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

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

Lecture Notes on Compositional Reasoning

Lecture Notes on Compositional Reasoning 15-414: Bug Catching: Automated Program Verification Lecture Notes on Compositional Reasoning Matt Fredrikson Ruben Martins Carnegie Mellon University Lecture 4 1 Introduction This lecture will focus on

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

CIS 500 Software Foundations. Final Exam. May 9, Answer key. Hoare Logic

CIS 500 Software Foundations. Final Exam. May 9, Answer key. Hoare Logic CIS 500 Software Foundations Final Exam May 9, 2011 Answer key Hoare Logic 1. (7 points) What does it mean to say that the Hoare triple {{P}} c {{Q}} is valid? Answer: {{P}} c {{Q}} means that, for any

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

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

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

Formal Methods for Java

Formal Methods for Java Formal Methods for Java Lecture 20: Sequent Calculus Jochen Hoenicke Software Engineering Albert-Ludwigs-University Freiburg January 15, 2013 Jochen Hoenicke (Software Engineering) Formal Methods for Java

More information

Central Algorithmic Techniques. Iterative Algorithms

Central Algorithmic Techniques. Iterative Algorithms Central Algorithmic Techniques Iterative Algorithms Code Representation of an Algorithm class InsertionSortAlgorithm extends SortAlgorithm { void sort(int a[]) throws Exception { for (int i = 1; i < a.length;

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

Verification Frameworks and Hoare Logic

Verification Frameworks and Hoare Logic CMSC 630 February 11, 2015 1 Verification Frameworks and Hoare Logic Sources K. Apt and E.-R. Olderog. Verification of Sequential and Concurrent Programs (Second Edition). Springer-Verlag, Berlin, 1997.

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

A Compositional Logic for Control Flow

A Compositional Logic for Control Flow A Compositional Logic for Control Flow Gang Tan and Andrew W. Appel Princeton University {gtan,appel}@cs.princeton.edu 10 Jan, 2005 Abstract We present a program logic, L c, which modularly reasons about

More information

Lecture 11: Measuring the Complexity of Proofs

Lecture 11: Measuring the Complexity of Proofs IAS/PCMI Summer Session 2000 Clay Mathematics Undergraduate Program Advanced Course on Computational Complexity Lecture 11: Measuring the Complexity of Proofs David Mix Barrington and Alexis Maciel July

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

CS 6110 Lecture 28 Subtype Polymorphism 3 April 2013 Lecturer: Andrew Myers

CS 6110 Lecture 28 Subtype Polymorphism 3 April 2013 Lecturer: Andrew Myers CS 6110 Lecture 28 Subtype Polymorphism 3 April 2013 Lecturer: Andrew Myers 1 Introduction In this lecture, we make an attempt to extend the typed λ-calculus for it to support more advanced data structures

More information

EDA045F: Program Analysis LECTURE 10: TYPES 1. Christoph Reichenbach

EDA045F: 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 information

Verification of Recursive Programs. Andreas Podelski February 8, 2012

Verification of Recursive Programs. Andreas Podelski February 8, 2012 Verification of Recursive Programs Andreas Podelski February 8, 2012 1 m(x) = x 10 if x > 100 m(m(x + 11)) if x 100 2 procedure m(x) returns (res) `0: if x>100 `1: res:=x-10 else `2: x m := x+11 `3: res

More information

Axiomatic Verification II

Axiomatic 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 information

3 Propositional Logic

3 Propositional Logic 3 Propositional Logic 3.1 Syntax 3.2 Semantics 3.3 Equivalence and Normal Forms 3.4 Proof Procedures 3.5 Properties Propositional Logic (25th October 2007) 1 3.1 Syntax Definition 3.0 An alphabet Σ consists

More information

Program Verification using Separation Logic Lecture 0 : Course Introduction and Assertion Language. Hongseok Yang (Queen Mary, Univ.

Program Verification using Separation Logic Lecture 0 : Course Introduction and Assertion Language. Hongseok Yang (Queen Mary, Univ. Program Verification using Separation Logic Lecture 0 : Course Introduction and Assertion Language Hongseok Yang (Queen Mary, Univ. of London) Dream Automatically verify the memory safety of systems software,

More information

Lecture 17: Floyd-Hoare Logic for Partial Correctness

Lecture 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 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

Equalities and Uninterpreted Functions. Chapter 3. Decision Procedures. An Algorithmic Point of View. Revision 1.0

Equalities and Uninterpreted Functions. Chapter 3. Decision Procedures. An Algorithmic Point of View. Revision 1.0 Equalities and Uninterpreted Functions Chapter 3 Decision Procedures An Algorithmic Point of View D.Kroening O.Strichman Revision 1.0 Outline Decision Procedures Equalities and Uninterpreted Functions

More information

CIS 500: Software Foundations

CIS 500: Software Foundations CIS 500: Software Foundations Midterm II November 8, 2016 Directions: This exam booklet contains both the standard and advanced track questions. Questions with no annotation are for both tracks. Other

More information

THE AUSTRALIAN NATIONAL UNIVERSITY Second Semester COMP2600 (Formal Methods for Software Engineering)

THE 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 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

Abstraction for Falsification

Abstraction for Falsification Abstraction for Falsification Thomas Ball 1, Orna Kupferman 2, and Greta Yorsh 3 1 Microsoft Research, Redmond, WA, USA. Email: tball@microsoft.com, URL: research.microsoft.com/ tball 2 Hebrew University,

More information