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

Size: px
Start display at page:

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

Transcription

1 Softwaretechnik Lecture 13: 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) Softwaretechnik / 54

3 Contracts for Procedural Programs Contracts for Procedural Programs Peter Thiemann (Univ. Freiburg) Softwaretechnik / 54

4 Contracts for Procedural Programs Reminder: 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) Softwaretechnik / 54

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) Softwaretechnik / 54

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) Softwaretechnik / 54

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) Softwaretechnik / 54

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) Softwaretechnik / 54

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) Softwaretechnik / 54

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) Softwaretechnik / 54

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) Softwaretechnik / 54

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) Softwaretechnik / 54

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) Softwaretechnik / 54

14 Contracts for Object-Oriented Programs Contracts for Object-Oriented Programs Peter Thiemann (Univ. Freiburg) Softwaretechnik / 54

15 Contracts for Object-Oriented Programs Contracts for Object-Oriented Programs Contracts for methods have additional complications 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) Softwaretechnik / 54

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 visible methods Peter Thiemann (Univ. Freiburg) Softwaretechnik / 54

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) Softwaretechnik / 54

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) Softwaretechnik / 54

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) Softwaretechnik / 54

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) Softwaretechnik / 54

21 Contracts for Object-Oriented Programs Method Specialization If MYTABLE redefines put then... the new precondition must be weaker and the new postcondition must be stronger because in TABLE cast = new MYTABLE (150);... cast.put (new Terminator (3), Arnie ); the caller only guaranties Pre put,table and expects Post put,table Peter Thiemann (Univ. Freiburg) Softwaretechnik / 54

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) Softwaretechnik / 54

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 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 sound method specialization because Post MYTABLE,put Post TABLE,insert Peter Thiemann (Univ. Freiburg) Softwaretechnik / 54

24 Contracts for Object-Oriented Programs Interlude: Method Specialization in 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 A extends B class C { A m () { return new A(); } } class D extends C { B m () { // overrides method C.m() return new B(); } } Peter Thiemann (Univ. Freiburg) Softwaretechnik / 54

25 Contract Monitoring Contract Monitoring Peter Thiemann (Univ. Freiburg) Softwaretechnik / 54

26 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) Softwaretechnik / 54

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 Contract Monitoring evaluates assertions at run time raises an exception indicating any violation assign blame for the violation Peter Thiemann (Univ. Freiburg) Softwaretechnik / 54

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 Why monitor? Debugging (with different levels of monitoring) Software fault tolerance (e.g., α and β releases) Peter Thiemann (Univ. Freiburg) Softwaretechnik / 54

29 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 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) Softwaretechnik / 54

30 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 on exit Post S,m must hold if Post S,m holds, then Post T,m must hold, too in general: cascade of implications between S and T pre- and postcondition only checked for S! If the precondition of S is not fulfilled, but the one of T is, then this is a wrong method specialization. Peter Thiemann (Univ. Freiburg) Softwaretechnik / 54

31 Contract Monitoring Examples interface IConsole { int { getmaxsize > 0 } void display (String { s.length () < this.getmaxsize() } } class Console implements IConsole { int getmaxsize () {... { getmaxsize > 0 } void display (String s) {... { s.length () < this.getmaxsize() } Peter Thiemann (Univ. Freiburg) Softwaretechnik / 54

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

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

34 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) Softwaretechnik / 54

35 Verification of Contracts Verification of Contracts Peter Thiemann (Univ. Freiburg) Softwaretechnik / 54

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

37 Verification of Contracts Syntax E ::= c x E + E... expressions B, P, Q ::= B P Q P Q boolean expressions E = E E E... C, D ::= 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) Softwaretechnik / 54

38 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) Softwaretechnik / 54

39 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) Softwaretechnik / 54

40 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 (σ) = B B σ = true F (S C σ), σ McCarthy conditional: b e 1, e 2 Peter Thiemann (Univ. Freiburg) Softwaretechnik / 54

41 Verification of Contracts Proving a Hoare triple {P} C {Q} holds if ( σ State) P(σ) (Q(S C σ) S C σ = ) (partial correctness) alternative reading/notation: P, Q State {P} C {Q} S C P Q reading predicates as boolean expressions B P σ = true (B Q (S C σ) = true S C σ = ) Peter Thiemann (Univ. Freiburg) Softwaretechnik / 54

42 Verification of Contracts Proof Rules for Hoare Triples Proving that {P} C {Q} holds directly from the definition is tedious 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) Softwaretechnik / 54

43 Verification of Contracts Skip Axiom {P} skip {P} Peter Thiemann (Univ. Freiburg) Softwaretechnik / 54

44 Verification of Contracts Skip Axiom {P} skip {P} Correctness S skip σ = σ S skip P = P Peter Thiemann (Univ. Freiburg) Softwaretechnik / 54

45 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) Softwaretechnik / 54

46 Verification of Contracts Assignment Axiom Correctness {P[x E]} x = E {P} Semantics S x=e σ = σ[x E E σ] Have to show B P[x E] σ = true (B P (S x = E σ) = true S x = E σ = ) By induction on P; result of B E ρe σ must remain the same; result of E E σ must remain the same Sufficient to show E E [x E] σ = E E σ[x E E σ] Holds because E x[x E] σ = E E σ = E x σ[x E E σ] Peter Thiemann (Univ. Freiburg) Softwaretechnik / 54

47 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) Softwaretechnik / 54

48 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} Correctness If σ P then σ = S C σ R { } If σ = then S D = If σ R then S D σ Q { } Hence: σ P S C; D σ Q { } Peter Thiemann (Univ. Freiburg) Softwaretechnik / 54

49 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) Softwaretechnik / 54

50 Verification of Contracts Conditional Rule {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 { } Exercize Peter Thiemann (Univ. Freiburg) Softwaretechnik / 54

51 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) Softwaretechnik / 54

52 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 if P true! similarly: P x 0 x == x Peter Thiemann (Univ. Freiburg) Softwaretechnik / 54

53 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 if P true! similarly: P x 0 x == x Correctness P P iff P P (as set of states) Peter Thiemann (Univ. Freiburg) Softwaretechnik / 54

54 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) Softwaretechnik / 54

55 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) Softwaretechnik / 54

56 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) Softwaretechnik / 54

57 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) Softwaretechnik / 54

58 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) Softwaretechnik / 54

59 Verification of Contracts Correctness of While-Rule {P B} C {P} {P} while B do C {P B} Consider S while B do C σ = F (σ) where F (σ) = B B σ = true F (S C σ), σ Case n N, B B (S C (n) σ) = true: set F (σ) =. Case n N, B B (S C (n) σ) = false: let n 0 be minimal Let σ P = (P B) (P B) Case n 0 = 0: σ P B, then F (σ) = σ P B. OK. Case n 0 > 0: σ P B, then σ = S C σ P { } by assumption. By induction, F (σ ) = S C (n 0 1) σ P B { } Peter Thiemann (Univ. Freiburg) Softwaretechnik / 54

60 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 is a challenging research topic: full automatization manageable for small/medium examples large examples require manual interaction real programs use arrays and dynamic datastructures (pointers, objects) Peter Thiemann (Univ. Freiburg) Softwaretechnik / 54

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

Software Engineering

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

More information

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

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

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

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

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

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

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

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

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

More information

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

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

More information

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

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

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

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

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

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

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

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

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

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

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

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 2016 Program Analysis and Verification. Lecture 3: Axiomatic Semantics I. Roman Manevich Ben-Gurion University

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

More information

Hoare Logic (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

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

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

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

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

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

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

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

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

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

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

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

More information

Proof 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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loop Invariants and Binary Search. Chapter 4.4, 5.1

Loop Invariants and Binary Search. Chapter 4.4, 5.1 Loop Invariants and Binary Search Chapter 4.4, 5.1 Outline Iterative Algorithms, Assertions and Proofs of Correctness Binary Search: A Case Study Outline Iterative Algorithms, Assertions and Proofs of

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

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

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

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

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

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

Learning Goals of CS245 Logic and Computation

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

More information

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

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

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

List reversal: back into the frying pan

List reversal: back into the frying pan List reversal: back into the frying pan Richard Bornat March 20, 2006 Abstract More than thirty years ago Rod Burstall showed how to do a proof of a neat little program, shown in a modern notation in figure

More information

CSE 331 Winter 2018 Homework 1

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

A JML Specification of the Design Pattern Visitor

A JML Specification of the Design Pattern Visitor A JML Specification of the Design Pattern Visitor Wolfgang Schreiner Research Institute for Symbolic Computation (RISC) Johannes Kepler University Linz, Austria Wolfgang.Schreiner@risc.jku.at September

More information

A Humble Introduction to DIJKSTRA S A A DISCIPLINE OF PROGRAMMING

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

More information

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

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

CS156: The Calculus of Computation

CS156: The Calculus of Computation CS156: The Calculus of Computation Zohar Manna Winter 2010 It is reasonable to hope that the relationship between computation and mathematical logic will be as fruitful in the next century as that between

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

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

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

Formal Verification with Ada 2012

Formal Verification with Ada 2012 Formal Verification with Ada 2012 A Very Simple Case Study Didier Willame Ada DevRoom, FOSEDM 2014 February 1, 2014 Content The Toy A Sandpile Simulator A Quick Reminder Floyd-Hoare Logic Design by Contract

More information

Program Verification as Probabilistic Inference

Program Verification as Probabilistic Inference Program Verification as Probabilistic Inference Sumit Gulwani Microsoft Research, Redmond sumitg@microsoft.com Nebojsa Jojic Microsoft Research, Redmond jojic@microsoft.com Abstract In this paper, we propose

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

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

Program Verification Using Separation Logic

Program Verification Using Separation Logic Program Verification Using Separation Logic Cristiano Calcagno Adapted from material by Dino Distefano Lecture 1 Goal of the course Study Separation Logic having automatic verification in mind Learn how

More information

Automata-Theoretic Model Checking of Reactive Systems

Automata-Theoretic Model Checking of Reactive Systems Automata-Theoretic Model Checking of Reactive Systems Radu Iosif Verimag/CNRS (Grenoble, France) Thanks to Tom Henzinger (IST, Austria), Barbara Jobstmann (CNRS, Grenoble) and Doron Peled (Bar-Ilan University,

More information