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

Size: px
Start display at page:

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

Transcription

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

2 Syllabus Semantics Static Analysis Abstract Interpretation fundamentals Analysis Techniques Crafting your own Natural Semantics Automating Hoare Logic Lattices Numerical Domains Soot Structural semantics Galois Connections CEGAR From proofs to abstractions Axiomatic Verification Fixed-Points Alias analysis Systematically developing transformers Widening/ Narrowing Shape Analysis Domain constructors Interprocedural Analysis 2

3 Previously Hoare logic Inference system Annotated programs Soundness and completeness Weakest precondition calculus 3

4 Axiomatic semantics for While [ass p ] [skip p ] { P[a/x] } x := a { P } { P } skip { P } [comp p ] { P } S 1 { Q }, { Q } S 2 { R } { P } S 1 ; S 2 { R } [if p ] { b P } S 1 { Q }, { b P } S 2 { Q } { P } if b then S 1 else S 2 { Q } [while p ] { b P } S { P } { P } while b do S { b P } [cons p ] { P } S { Q } { P } S { Q } if P P and Q Q 4

5 Weakest precondition calculus 5

6 Weakest liberal precondition A backward-going predicate transformer The weakest liberal precondition for Q is wlp(c, Q) if and only if for all states if C, then Q Propositions: 1. p { wlp(c, Q) } C { Q } 2. If p { P } C { Q } then P wlp(c, Q) 6

7 Weakest liberal precondition A backward-going predicate transformer The weakest liberal precondition for Q is wlp(c, Q) if and only if for all states if C, then Q wlp(c, Q) P Q C(wlp(C, Q)) C C(P) 7

8 Strongest postcondition A forward-going predicate transformer The strongest postcondition for P is sp(p, C) if and only if there exists such that P and C, Propositions: 1. p { P } C { sp(p, C) } 2. If p { P } C { Q } then sp(p, C) Q 8

9 Calculating Weakest preconditions By Vadim Plessky ( [see page for license], via Wikimedia Commons 9

10 Calculating wlp 1. wlp(skip, Q) = Q 2. wlp(x := a, Q) = Q[a/x] 3. wlp(s 1 ; S 2, Q) = wlp(s 1, wlp(s 2, Q)) 4. wlp(if b then S 1 else S 2, Q) = (b wlp(s 1, Q)) ( b wlp(s 2, Q)) 5. wlp(while b do S, Q) =? hard to capture 10

11 Calculating the wlp of a loop Idea: we know the following statements are semantically equivalent while b do S if b do (S; while b do S) else skip Let s try to substitute and calculate on wlp(while b do S, Q) = wlp(if b do (S; while b do S) else skip, Q) = (b wlp(s; while b do S, Q)) ( b wlp(skip, Q)) = (b wlp(s, wlp(while b do S, Q))) ( b Q) LoopInv = (b wlp(s, LoopInv)) ( b Q) 11

12 Another variant for WP of loops Parametric in the loop invariant wlp(while b do { } S, Q) = where {b } S { } and b Q 12

13 Variable swap program specify {? } t := x x := y y := t {? } 13

14 Prove using weakest precondition { y=b x=a } t := x {? } x := y {? } y := t { x=b y=a } 14

15 Prove using weakest precondition { y=b x=a } t := x { y=b t=a } x := y { x=b t=a } y := t { x=b y=a } 15

16 Absolute value program if x<0 then else x := -x skip if b then S is syntactic sugar for if b then S else skip The latter form is easier to reason about 16

17 Absolute value program specify {? } if x<0 then x := -x else skip {? } 17

18 Absolute value program specify { x=v } if x<0 then x := -x else skip { x= v } 18

19 Prove using weakest precondition { x=v } { } if x<0 then { } x := -x { } else { } skip { } {x= v } 19

20 Prove using weakest precondition { x=v } { (-x= v x<0) (x= v x 0) } if x<0 then { -x= v } x := -x { x= v } else { x= v } skip { x= v } { x= v } 20

21 Making the proof system more practical 21

22 Conjunction rule [conj p ] { P } S { Q } { P } S { Q } { P P } S {Q Q } Allows breaking up proofs into smaller, easier to manage, sub-proofs 22

23 Breaks if C is nondeterministic [disj p ] More useful rules { P } C { Q } { P } C { Q } { P P } C {Q Q } [exist p ] { P } C { Q } { v. P } C { v. Q } v FV(C) { P } C { Q } [univ p ] { v. P } C { v. Q } v FV(C) [Inv p ] { F } C { F } Mod(C) FV(F)={} Mod(C) = set of variables assigned to in sub-statements of C FV(F) = free variables of F 23

24 Invariance + Conjunction = Constancy [constancy p ] { P } C { Q } { F P } C { F Q } Mod(C) FV(F)={} Mod(C) = set of variables assigned to in sub-statements of C FV(F) = free variables of F 24

25 Today Strongest postcondition Extension for memory Proving termination 25

26 Strongest postcondition calculus By Vadim Plessky ( [see page for license], via Wikimedia Commons 26

27 Floyd s strongest postcondition rule [ass Floyd ] { P } x := a { v. x=a[v/x] P[v/x] } where v is a fresh variable The value of x in the pre-state Example { z=x } x:=x+1 {? } This rule is often considered problematic because it introduces a quantifier needs to be eliminated further on We will now see a variant of this rule 27

28 Floyd s strongest postcondition rule [ass Floyd ] { P } x := a { v. x=a[v/x] P[v/x] } where v is a fresh variable meaning: {x=z+1} Example { z=x } x:=x+1 { v. x=v+1 z=v } This rule is often considered problematic because it introduces a quantifier needs to be eliminated further on We will now see a variant of this rule 28

29 Small assignment axiom Create an explicit Skolem variable in precondition Then assign the resulting value to x First evaluate a in the precondition state (as a may access x) [ass floyd ] { x=v } x:=a { x=a[v/x] } where v FV(a) Examples: {x=n} x:=5*y {x=5*y} {x=n} x:=x+1 {x=n+1} {x=n} x:=y+1 {x=y+1} [exist p ] { n. x=n} x:=y+1 { n. x=y+1} therefore {true} x:=y+1 {x=y+1} [constancy p ] {z=9} x:=y+1 {z=9 x=y+1} 29

30 Small assignment axiom [ass { x=v } x:=a { x=a[v/x] } floyd ] Examples: {x=n} x:=5*y {x=5*y} {x=n} x:=x+1 {x=n+1} where v FV(a) {x=n} x:=y+1 {x=y+1} [exist p ] { n. x=n} x:=y+1 { n. x=y+1} therefore {true} x:=y+1 {x=y+1} [constancy p ] {z=9} x:=y+1 {z=9 x=y+1} 30

31 Small assignment axiom [ass { x=v } x:=a { x=a[v/x] } floyd ] Examples: {x=n} x:=5*y {x=5*y} {x=n} x:=x+1 {x=n+1} where v FV(a) {x=n} x:=y+1 {x=y+1} [exist p ] { n. x=n} x:=y+1 { n. x=y+1} therefore {true} x:=y+1 {x=y+1} [constancy p ] {z=9} x:=y+1 {z=9 x=y+1} 31

32 Small assignment axiom [ass { x=v } x:=a { x=a[v/x] } floyd ] Examples: {x=n} x:=5*y {x=5*y} {x=n} x:=x+1 {x=n+1} where v FV(a) {x=n} x:=y+1 {x=y+1} [exist p ] { n. x=n} x:=y+1 { n. x=y+1} therefore {true} x:=y+1 {x=y+1} [constancy p ] {z=9} x:=y+1 {z=9 x=y+1} 32

33 1. sp(skip, P) = P Calculating sp 2. sp(x := a, P) = v. x=a[v/x] P[v/x] 3. sp(s 1 ; S 2, P) = sp(s 2, sp(s 1, P)) 4. sp(if b then S 1 else S 2, P) = sp(s 1, b P) sp(s 2, b P) 5. sp(while b do { } S, P) = b where {b } S { } and P b 33

34 Prove using strongest postcondition { x=a y=b } t := x x := y y := t { x=b y=a } 34

35 Prove using strongest postcondition { x=a y=b } t := x { x=a y=b t=a } x := y y := t { x=b y=a } 35

36 Prove using strongest postcondition { x=a y=b } t := x { x=a y=b t=a } x := y { x=b y=b t=a } y := t { x=b y=a } 36

37 Prove using strongest postcondition { x=a y=b } t := x { x=a y=b t=a } x := y { x=b y=b t=a } y := t { x=b y=a t=a } { x=b y=a } // cons 37

38 Prove using strongest postcondition { x=v } if x<0 then { x=v x<0 } x := -x { x=-v x>0 } else { x=v x 0 } skip { x=v x 0 } { v<0 x=-v v 0 x=v } { x= v } 38

39 Prove using strongest postcondition { x=v } if x<0 then { x=v x<0 } x := -x { x=-v x>0 } else { x=v x 0 } skip { x=v x 0 } { v<0 x=-v v 0 x=v } { x= v } 39

40 Sum program specify Define Sum(0, n) = n {? } x := 0 res := 0 while (x<y) do res := res+x x := x+1 {? } { x=sum(0, n) } { y=n+1 } { x+y=sum(0, n+1) } Background axiom 40

41 Sum program specify Define Sum(0, n) = n { y 0 } x := 0 res := 0 while (x<y) do res := res+x x := x+1 { res = Sum(0, y) } { x=sum(0, n) } { y=n+1 } { x+y=sum(0, n+1) } Background axiom 41

42 Sum program prove Define Sum(0, n) = n { x=sum(0, n) } { y=n+1 } { x+y=sum(0, n+1) } { y 0 } x := 0 res := 0 Inv = while (x<y) do res := res+x x := x+1 { res = Sum(0, y) } 42

43 Sum program prove Define Sum(0, n) = n { x=sum(0, n) } { y=n+1 } { x+y=sum(0, n+1) } { y 0 } x := 0 { y 0 x=0 } res := 0 Inv = while (x<y) do res := res+x x := x+1 { res = Sum(0, y) } 43

44 Sum program prove Define Sum(0, n) = n { x=sum(0, n) } { y=n+1 } { x+y=sum(0, n+1) } { y 0 } x := 0 { y 0 x=0 } res := 0 { y 0 x=0 res=0 } Inv = while (x<y) do res := res+x x := x+1 { res = Sum(0, y) } 44

45 Sum program prove Define Sum(0, n) = n { x=sum(0, n) } { y=n+1 } { x+y=sum(0, n+1) } { y 0 } x := 0 { y 0 x=0 } res := 0 { y 0 x=0 res=0 } Inv = { y 0 res=sum(0, x) x y } while (x<y) do res := res+x x := x+1 { res = Sum(0, y) } 45

46 Sum program prove Define Sum(0, n) = n { x=sum(0, n) } { y=n+1 } { x+y=sum(0, n+1) } { y 0 } x := 0 { y 0 x=0 } res := 0 { y 0 x=0 res=0 } Inv = { y 0 res=sum(0, x) x y } while (x<y) do { y 0 res=m x=n n y m=sum(0, n) x<y } { y 0 res=m x=n m=sum(0, n) n<y } res := res+x x := x+1 { res = Sum(0, y) } 46

47 Sum program prove Define Sum(0, n) = n { x=sum(0, n) } { y=n+1 } { x+y=sum(0, n+1) } { y 0 } x := 0 { y 0 x=0 } res := 0 { y 0 x=0 res=0 } Inv = { y 0 res=sum(0, x) x y } while (x<y) do { y 0 res=m x=n n y m=sum(0, n) x<y } { y 0 res=m x=n m=sum(0, n) n<y } res := res+x { y 0 res=m+x x=n m=sum(0, n) n<y } x := x+1 { res = Sum(0, y) } 47

48 Sum program prove Define Sum(0, n) = n { x=sum(0, n) } { y=n+1 } { x+y=sum(0, n+1) } { y 0 } x := 0 { y 0 x=0 } res := 0 { y 0 x=0 res=0 } Inv = { y 0 res=sum(0, x) x y } while (x<y) do { y 0 res=m x=n n y m=sum(0, n) x<y } { y 0 res=m x=n m=sum(0, n) n<y } res := res+x { y 0 res=m+x x=n m=sum(0, n) n<y } x := x+1 { y 0 res=m+x x=n+1 m=sum(0, n) n<y } { y 0 res=sum(0, x) x=n+1 n<y } // sum axiom { y 0 res=sum(0, x) x y } // cons { res = Sum(0, y) } 48

49 Sum program prove Define Sum(0, n) = n { x=sum(0, n) } { y=n+1 } { x+y=sum(0, n+1) } { y 0 } x := 0 { y 0 x=0 } res := 0 { y 0 x=0 res=0 } Inv = { y 0 res=sum(0, x) x y } while (x<y) do { y 0 res=m x=n n y m=sum(0, n) x<y } { y 0 res=m x=n m=sum(0, n) n<y } res := res+x { y 0 res=m+x x=n m=sum(0, n) n<y } x := x+1 { y 0 res=m+x x=n+1 m=sum(0, n) n<y } { y 0 res=sum(0, x) x=n+1 n<y } // sum axiom { y 0 res=sum(0, x) x y } // cons { y 0 res=sum(0, x) x y x y } { y 0 res=sum(0, y) x=y } { res = Sum(0, y) } 49

50 Buggy sum program { y 0 } x := 0 { y 0 x=0 } res := 0 { y 0 x=0 res=0 } Inv = { y 0 res=sum(0, x) } = { y 0 res=m x=n m=sum(0, n) } while (x y) do { y 0 res=m x=n m=sum(0, n) x y n y } x := x+1 { y 0 res=m x=n+1 m=sum(0, n) n y} res := res+x { y 0 res=m+x x=n+1 m=sum(0, n) n y} { y 0 res-x=sum(0, x-1) n y} { y 0 res=sum(0, x) } { y 0 res=sum(0, x) x>y } {res = Sum(0, y) } 50

51 Handling data structures 51

52 Problems with Hoare logic and heaps { P[a/x] } x := a { P } Consider the annotated program { y=5 } y := 5; { y=5 } x := &y; { y=5 } *x := 7; { y=5 } Is it correct? The rule works on a syntactic level unaware of possible aliasing between different terms (y and *x in our case) 52

53 Problems with Hoare logic and heaps { P[a/x] } x := a { P } {(x=&y z=5) (x &y y=5)} *x = z; { y=5 } What should the precondition be? 53

54 Problems with Hoare logic and heaps { P[a/x] } x := a { P } {(x=&y z=5) (x &y y=5)} *x = z; { y=5 } We split into cases depending on possible aliasing 54

55 Problems with Hoare logic and heaps { P[a/x] } x := a { P } {(x=&y z=5) (x &y y=5)} *x = z; { y=5 } What should the precondition be? Joseph M. Morris: A General Axiom of Assignment A different approach: heaps as arrays Really successful approach for heaps is based on Separation Logic 55

56 Axiomatizing data types S ::= x := a x := y[a] y[a] := x skip S 1 ; S 2 if b then S 1 else S 2 while b do S We added a new type of variables array variables Model array variable as a function y : Z Z We need the two following axioms: { y[x a](x) = a } { z x y[x a](z) = y(z) } 56

57 Array update rules (wlp) S ::= x := a x := y[a] y[a] := x skip S 1 ; S 2 if b then S 1 else S 2 while b do S Treat an array assignment y[a] := x as an update to the array function y y := y[a x] meaning y = v. v=a? x : y(v) A very general approach allows handling many data types [array-update] { P[y[a x]/y] } y[a] := x { P } [array-load] { P[y(a)/x] } x := y[a] { P } 57

58 Array update rules (wlp) example Treat an array assignment y[a] := x as an update to the array function y y := y[a x] meaning y = v. v=a? x : y(v) [array-update] { P[y[a x]/y] } y[a] := x { P } {x=y[i 7](i)} y[i]:=7 {x=y(i)} {x=7} y[i]:=7 {x=y(i)} [array-load] { P[y(a)/x] } x := y[a] { P } {y(a)=7} x:=y[a] {x=7} 58

59 Array update rules (sp) In both rules v, g, and b are fresh [array-update F ] { x=v y=g a=b } y[a] := x { y=g[b v] } [array-load F ] { y=g a=b } x := y[a] { x=g(b) } 59

60 Example of proving program with arrays 60

61 Array-max program specify nums : array N : int // N stands for num s length { N 0 nums=orig_nums } x := 0 res := nums[0] while x < N if nums[x] > res then res := nums[x] x := x { x=n } 2. { m. (m 0 m<n) nums(m) res } 3. { m. m 0 m<n nums(m)=res } 4. { nums=orig_nums } 61

62 Array-max program nums : array N : int // N stands for num s length { N 0 nums=orig_nums } x := 0 res := nums[0] while x < N if nums[x] > res then res := nums[x] x := x + 1 Post 1 : { x=n } Post 2 : { nums=orig_nums } Post 3 : { m. 0 m<n nums(m) res } Post 4 : { m. 0 m<n nums(m)=res } 62

63 Proof strategy Prove each goal 1, 2, 3, 4 separately and use conjunction rule to prove them all After proving {N 0} C {x=n} {nums=orig_nums} C {nums=orig_nums} We have proved {N 0 nums=orig_nums} C {x=n nums=orig_nums} We can refer to assertions from earlier proofs in writing new proofs 63

64 Array-max example: Post 1 nums : array N : int // N stands for num s length { N 0 } x := 0 { N 0 x=0 } res := nums[0] { x=0 } Inv = { x N } while x < N { x=k k<n } if nums[x] > res then { x=k k<n } res := nums[x] { x=k k<n } { x=k k<n } x := x + 1 { x=k+1 k<n } { x N x N } { x=n } 64

65 Array-max example: Post 2 nums : array N : int // N stands for num s length { nums=orig_nums } x := 0 { nums=orig_nums } res := nums[0] { nums=orig_nums } Inv = { nums=orig_nums } while x < N { nums=orig_nums x < N } if nums[x] > res then { nums=orig_nums } res := nums[x] { nums=orig_nums } { nums=orig_nums } x := x + 1 { nums=orig_nums } { nums=orig_nums x N } { nums=orig_nums } 65

66 Array-max example: Post 3 nums : array { N 0 0 m<n } // N stands for num s length x := 0 { x=0 } res := nums[0] { x=0 res=nums(0) } Inv = { 0 m<x nums(m) res } while x < N { x=k res=ores 0 m<k nums(m) ores } if nums[x] > res then { nums(x)>ores res=ores x=k 0 m<k nums(m) ores } res := nums[x] { res=nums(x) nums(x)>ores x=k 0 m<k nums(m) ores } { x=k 0 m k nums(m) res } { (x=k 0 m k nums(m) res) (ores nums(x) res=ores x=k res=ores 0 m<k nums(m) ores)} { x=k 0 m k nums(m) res } x := x + 1 { x=k+1 0 m k nums(m) res } { 0 m<x nums(m) res } { x=n 0 m<x nums(m) res} [univ p ]{ m. 0 m<n nums(m) res } 66

67 Proving termination 67

68 Total correctness semantics for While [ass p ] [skip p ] [comp p ] [if p ] [while p ] [ P[a/x] ] x := a [ P ] [ P ] skip [ P ] [ P ] S 1 [ Q ], [ Q ] S 2 [ R ] [ P ] S 1 ; S 2 [ R ] [ b P ] S 1 [ Q ], [ b P ] S 2 [ Q ] [ P ] if b then S 1 else S 2 [ Q ] [ P(z+1) ] S [ P(z) ] [ z. P(z) ] while b do S [ P(0) ] P(z+1) b P(0) b [cons p ] [ P ] S [ Q ] [ P ] S [ Q ] if P P and Q Q 68

69 Total correctness semantics for While Rank, or Loop variant [ass p ] [skip p ] [comp p ] [if p ] [while p ] [ P[a/x] ] x := a [ P ] [ P ] skip [ P ] [ P ] S 1 [ Q ], [ Q ] S 2 [ R ] [ P ] S 1 ; S 2 [ R ] [ b P ] S 1 [ Q ], [ b P ] S 2 [ Q ] [ P ] if b then S 1 else S 2 [ Q ] [ b P t=k ] S [ P t<k ] [ P ] while b do S [ b P ] P t 0 [cons p ] [ P ] S [ Q ] [ P ] S [ Q ] if P P and Q Q 69

70 Proving termination There is a more general rule based on wellfounded relations Partial orders with no infinite strictly decreasing chains Exercise: write a rule that proves only that a program S, started with precondition P terminates [ ] S [ ] 70

71 Proving termination There is a more general rule based on wellfounded relations Partial orders with no infinite strictly decreasing chains Exercise: write a rule that proves only that a program S, started with precondition P terminates [ P ] S [ true ] 71

72 Array-max specify termination nums : array N : int // N stands for num s length x := 0 res := nums[0] Variant = [? ] while x < N if nums[x] > res then res := nums[x] x := x + 1 [? ] 72

73 Array-max specify termination nums : array N : int // N stands for num s length x := 0 res := nums[0] Variant = [ N-x ] while x < N [? ] if nums[x] > res then res := nums[x] x := x + 1 [? ] [ true ] 73

74 Array-max prove loop variant nums : array N : int // N stands for num s length x := 0 res := nums[0] Variant = [ t=n-x ] while x < N [ x<n N-x=k N-x 0 ] if nums[x] > res then res := nums[x] x := x + 1 // [ N-x<k N-x 0 ] [ true ] 74

75 Array-max prove loop variant nums : array N : int // N stands for num s length x := 0 res := nums[0] Variant = [ t=n-x ] while x < N Capture initial value of x, since it changes in the loop [ x=x0 x0<n N-x0=k N-x0 0 ] if nums[x] > res then res := nums[x] x := x + 1 // [ N-x<k N-x 0 ] [ true ] 75

76 Array-max prove loop variant nums : array N : int // N stands for num s length x := 0 res := nums[0] Variant = [ t=n-x ] while x < N [ x=x0 x0<n N-x0=k N-x0 0 ] if nums[x] > res then res := nums[x] [ x=x0 x0<n N-x0=k N-x0 0 ] // Frame x := x + 1 // [ N-x<k N-x 0 ] [ true ] 76

77 Array-max prove loop variant nums : array N : int // N stands for num s length x := 0 res := nums[0] Variant = [ t=n-x ] while x < N [ x=x0 x0<n N-x0=k N-x0 0 ] if nums[x] > res then res := nums[x] [ x=x0 x0<n N-x0=k N-x0 0 ] // Frame x := x + 1 [ x=x0+1 x0<n N-x0=k N-x0 0 ] // [ N-x<k N-x 0 ] [ true ] 77

78 Array-max prove loop variant nums : array N : int // N stands for num s length x := 0 res := nums[0] Variant = [ t=n-x ] while x < N [ x=x0 x0<n N-x0=k N-x0 0 ] if nums[x] > res then res := nums[x] [ x=x0 x0<n N-x0=k N-x0 0 ] // Frame x := x + 1 [ x=x0+1 x0<n N-x0=k N-x0 0 ] [ N-x<k N-x 0 ] // cons [ true ] 78

79 Zune calendar bug while (days > 365) { if (IsLeapYear(year)) { if (days > 366) { days -= 366; year += 1; } } } else { days -= 365; year += 1; } 79

80 Fixed code while (days > 365) { if (IsLeapYear(year)) { if (days > 366) { days -= 366; year += 1; } else { break; } } else { days -= 365; year += 1; } } 80

81 Fixed code specify termination [? ] while (days > 365) { if (IsLeapYear(year)) { if (days > 366) { days -= 366; year += 1; } else { break; } } else { days -= 365; year += 1; } } [? ] 81

82 Fixed code specify variant [ true ] Variant = [? ] while (days > 365) { if (IsLeapYear(year)) { if (days > 366) { days -= 366; year += 1; } else { break; } } else { days -= 365; year += 1; } [? ] } [ true ] 82

83 Fixed code proving termination [ true ] Variant = [ t=days ] while (days > 365) { [ days>365 days=k days 0 ] if (IsLeapYear(year)) { if (days > 366) { days -= 366; year += 1; } else { break; [ false ] } } else { days -= 365; year += 1; } // [ days 0 days<k ] } [ true ] Let s model break by a small cheat assume execution never gets past it 83

84 Fixed code proving termination [ true ] Variant = [ t=days ] while (days > 365) { [ days 0 k=days days>365 ] -> [ days 0 k=days days>365 ] if (IsLeapYear(year)) { } [ k=days days>365 ] if (days > 366) { [ k=days days>365 days>366 ] -> [ k=days days>366 ] days -= 366; [ days=k-366 days>0 ] year += 1; [ days=k-366 days>0 ] } else { [ k=days days>365 days 366 ] break; [ false ] } [ (days=k-366 days>0) false ] -> [ days<k days>0 ] } else { [ k=days days>365 ] days -= 365; [ k-365=days days-365>365 ] -> [ k-365=days days 0 ] -> [ days<k days 0 ] year += 1; [ days<k days 0 ] [ days<k days 0 ] } [ true ] 84

85 Challenge: proving non-termination Write a rule for proving that a program does not terminate when started with a precondition P Prove that the buggy Zune calendar program does not terminate [while-nt p ] { b P } S { b } { P } while b do S { false } 85

86 conclusion 86

87 Extensions to axiomatic semantics Assertions for execution time Exact time Order of magnitude time Assertions for dynamic memory Separation Logic Assertions for parallelism Owicki-Gries Concurrent Separation Logic Rely-guarantee 87

88 Axiomatic verification conclusion Very powerful technique for reasoning about programs Sound and complete Extendible Static analysis can be used to automatically synthesize assertions and loop invariants 88

89 Next lecture: static analysis

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

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

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

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

More information

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

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

More information

Predicate Transforms I

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

More information

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

CS558 Programming Languages

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

More information

Deductive Verification

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

More information

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Strength; Weakest Preconditions

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

More information

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

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

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

More information

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

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

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

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

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

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

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

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

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

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

Galois Connections. Roland Backhouse 3rd December, 2002

Galois Connections. Roland Backhouse 3rd December, 2002 1 Galois Connections Roland Backhouse 3rd December, 2002 Fusion 2 Many problems are expressed in the form evaluate generate where generate generates a (possibly infinite) candidate set of solutions, and

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

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

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

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

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

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

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

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

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

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

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

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

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

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

More information

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

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

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

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

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

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

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

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

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

Adam Blank Spring 2017 CSE 311. Foundations of Computing I

Adam Blank Spring 2017 CSE 311. Foundations of Computing I Adam Blank Spring 2017 CSE 311 Foundations of Computing I Pre-Lecture Problem Suppose that p, and p (q r) are true. Is q true? Can you prove it with equivalences? CSE 311: Foundations of Computing Lecture

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

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

Model Checking: An Introduction

Model Checking: An Introduction Model Checking: An Introduction Meeting 3, CSCI 5535, Spring 2013 Announcements Homework 0 ( Preliminaries ) out, due Friday Saturday This Week Dive into research motivating CSCI 5535 Next Week Begin foundations

More information

Static Program Analysis

Static Program Analysis Static Program Analysis Xiangyu Zhang The slides are compiled from Alex Aiken s Michael D. Ernst s Sorin Lerner s A Scary Outline Type-based analysis Data-flow analysis Abstract interpretation Theorem

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

Chapter 3. Specifications. 3.1 Hoare Triples. An Introduction to Separation Logic c 2011 John C. Reynolds February 3, 2011

Chapter 3. Specifications. 3.1 Hoare Triples. An Introduction to Separation Logic c 2011 John C. Reynolds February 3, 2011 Chapter 3 An Introduction to Separation Logic c 2011 John C. Reynolds February 3, 2011 Specifications From assertions, we move on to specifications, which describe the behavior of commands. In this chapter,

More information

Notation for Logical Operators:

Notation for Logical Operators: Notation for Logical Operators: always true always false... and...... or... if... then...... if-and-only-if... x:x p(x) x:x p(x) for all x of type X, p(x) there exists an x of type X, s.t. p(x) = is equal

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

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

Static Program Analysis using Abstract Interpretation

Static Program Analysis using Abstract Interpretation Static Program Analysis using Abstract Interpretation Introduction Static Program Analysis Static program analysis consists of automatically discovering properties of a program that hold for all possible

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

Logical Abstract Domains and Interpretations

Logical Abstract Domains and Interpretations Logical Abstract Domains and Interpretations Patrick Cousot 2,3, Radhia Cousot 3,1, and Laurent Mauborgne 3,4 1 Centre National de la Recherche Scientifique, Paris 2 Courant Institute of Mathematical Sciences,

More information

Propositional Logic: Deductive Proof & Natural Deduction Part 1

Propositional Logic: Deductive Proof & Natural Deduction Part 1 Propositional Logic: Deductive Proof & Natural Deduction Part 1 CS402, Spring 2016 Shin Yoo Deductive Proof In propositional logic, a valid formula is a tautology. So far, we could show the validity of

More information

Verifying Properties of Parallel Programs: An Axiomatic Approach

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

More information

Programming Languages

Programming Languages CSE 230: Winter 2008 Principles of Programming Languages Lecture 7: Axiomatic Semantics Axiomatic Semantics over low Graphs c {P} if P P {P } {Q} c if Q Q {Q} {Q } Ranjit Jhala UC San Diego Relaxing specifications

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

(La méthode Event-B) Proof. Thanks to Jean-Raymond Abrial. Language of Predicates.

(La méthode Event-B) Proof. Thanks to Jean-Raymond Abrial. Language of Predicates. CSC 4504 : Langages formels et applications (La méthode Event-B) J Paul Gibson, A207 paul.gibson@it-sudparis.eu http://www-public.it-sudparis.eu/~gibson/teaching/event-b/ Proof http://www-public.it-sudparis.eu/~gibson/teaching/event-b/proof.pdf

More information

Structuring the verification of heap-manipulating programs

Structuring the verification of heap-manipulating programs Structuring the verification of heap-manipulating programs Aleksandar Nanevski (IMDEA Madrid) Viktor Vafeiadis (MSR / Univ. of Cambridge) Josh Berdine (MSR Cambridge) Hoare/Separation Logic Hoare logic

More information

Problem Sheet 1: Axiomatic Semantics

Problem Sheet 1: Axiomatic Semantics Problem Sheet 1: Axiomatic Semantics Chris Poskitt ETH Zürich Starred exercises ( ) are more challenging than the others. 1 Partial and Total Correctness Recall the Hoare triple from lectures, {pre} P

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

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

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

More information