Formal Methods in Software Engineering
|
|
- Christine Adams
- 5 years ago
- Views:
Transcription
1 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) Formal Methods in SW Engineering Fall / 187
2 Orientation Vesal Vojdani Department of Computer Science University of Tartu Formal Methods (2014) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
3 What are formal methods? formal method = formal model + formal analysis Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
4 What is a formal model? A model is formal if it has... Well-defined syntax. Unambiguous 1 semantics. 1 mathematical Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
5 Formal Analysis 1. Automated Theorem Proving 2. Model Checking 3. Abstract Interpretation Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
6 In General M ϕ M: a situation or model of the system ϕ: a specification of what should hold at situation M Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
7 Where do models come from? 1. Hand-written from informal specs. 2. Derived automatically from source code. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
8 Why create a model? You can use the model to 1. analyze if the model behaves well. 2. test if the implementation conforms to it. For this to be worth it, model must be simpler than actual implementation. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
9 Model-Based Analysis Model may be simple, but... execution may be complex (concurrency!) Visualize the state graph: manually check functional conformance to informal spec. Automatically check all states of the model for safety and liveness properties. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
10 Model-Based Testing Automatic test generation requires an oracle. The model can be used to automatically generate unit tests with all checks and assertions inserted. We can ensure coverage criteria with respect to all states of the model. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
11 Inferring models from code The code itself is a formal model! It is usually not possible to analyze directly. We need bounds and abstractions. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
12 The goal of this course Where should you be in one year? You are qualified to engage in research to either develop novel verification techniques or apply current techniques in novel contexts. Where should you do this work? Our (PLAS) research group! One of the many Estonian companies that are producing novel tools for the maintenance of complex systems. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
13 Must Work Harder There will be weekly exercise sheets. They will be made available on Friday. You may ask questions on Wednesday. You will submit electronically on Wednesday evening. We will discuss on Friday. Three programming projects. Probably as group work. You may replace this with equivalent thesis work if your supervisor agrees. A final exam. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
14 Hoare Logic Vesal Vojdani Department of Computer Science University of Tartu Formal Methods (2014) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
15 Hoare Triplets φ P ψ A Hoare triple is satisfied under partial correctness: for each state satisfying φ, if execution reaches the end of P, the resulting state satisfies ψ. (Total correctness: partial + termination) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
16 Simple Language C ::= C 1 ; C 2 x := e if e then C 1 else C 2 while e do C skip {C} Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
17 FOL with linear arithmetic φ ::= e arithmetic φ 1 φ 2 conjunction φ 1 φ 2 disjunction φ 1 φ 2 implication y : φ existential quantification y : φ universal quantification. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
18 Composition φ C 1 η η C 2 ψ φ C 1 ; C 2 ψ Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
19 Assignment ψ[e/x] x = e ψ Is this backwards? Consider examples for x := 2 and x := x + 1. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
20 Conditional Statements φ e C 1 ψ φ e C 2 ψ φ if e then C 1 else C 2 ψ Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
21 While Statements φ e C φ φ while e do C φ e Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
22 Implication φ φ φ C ψ ψ ψ φ C ψ These end up as verification conditions. Automated theorem provers have to dispatch them. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
23 Hello World! int abs(int i) { if (0 <= i) r := i; else r := -i; } Prove: always returns a non-negative value. (Where exactly would an overflow invalidate this proof?) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
24 Step by step 1. We first have the conditional: 0 i r := i 0 r i < 0 r := i 0 r true if 0 i then r := i else r := i 0 r 2. The true-branch follows from the assignment axiom. 3. The false-branch relies on a simple implication: i < 0 0 i 0 i r := i 0 r i < 0 r := i 0 r Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
25 Proof trees i < 0 0 i 0 i r := i 0 r 0 i r := i 0 r i < 0 r := i 0 r true if 0 i then r := i else r := i 0 r The sequential application of inference rules are often represented as proof trees. These trees can grow large... Instead: annotate the program code! Tree structure is implicit. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
26 Tableaux Proofs φ 0 C 1 ; φ 1 C 2 ; φ 2. φ n 1 C n φ n Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
27 Tableaux: Composition φ C 1 η η C 2 ψ φ C 1 ; C 2 ψ φ C 1 ; η C 2 ψ Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
28 Tableaux: Conditional φ e C 1 ψ φ e C 2 ψ φ if e then C 1 else C 2 ψ φ if e then { φ e C 1 ψ } else { φ e C 2 ψ } ψ Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
29 Tableaux: Conditional φ if e then { φ e C 1 φ e C 1 ψ φ e C 2 ψ φ if e then C 1 else C 2 ψ } else { C 2 φ e } ψ Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
30 Tableaux: Implication φ φ φ C ψ ψ ψ φ C ψ φ φ C ψ ψ Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
31 The example as tableaux proof true if (0 i) then { true 0 i r := i 0 r } else { true i < 0 0 i r := i 0 r } 0 r Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
32 Weakest Pre-Conditions We have so far only rules for valid Hoare triples. Not all triples are equally useful false P ψ How do we infer these triples? We will now move towards a more syntax-driven method to infer weakest pre-conditions. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
33 Definition We say φ is weaker than φ if φ φ For φ = WP S ψ, we have φ S ψ is valid if φ S ψ then φ φ ψ holds after S iff φ holds before. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
34 Assignment Consider sequential composition: z := x; z := z + y; u := z It suffices with definitions: WP x = e ψ = ψ[e/x] WP C 1 ; C 2 ψ = WP C 1 (WP C 2 ψ) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
35 A tableaux proof from WPs x + y = 42 z := x; z + y = 42 z := z + y; z = 42 u := z u = 42 Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
36 Conditional Hoare logic: φ e C 1 ψ φ e C 2 ψ φ if e then C 1 else C 2 ψ A more syntax-driven rule: φ 1 C 1 ψ φ 2 C 2 ψ φ if e then C 1 else C 2 ψ where φ = (e φ 1 ) ( e φ 2 ) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
37 Proof Tableaux for Conditional 2.0 if e then { C 1 } else { } C 2 ψ Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
38 Proof Tableaux for Conditional 2.0 if e then { WP C 1 ψ C 1 } else { WP C 2 ψ C 2 } ψ Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
39 Proof Tableaux for Conditional 2.0 (e WP C 1 ψ) ( e WP C 2 ψ) if e then { WP C 1 ψ C 1 } else { WP C 2 ψ C 2 } ψ Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
40 The Example Again if (0 i) then { r := i } else { } r := i 0 r Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
41 The Example Again if (0 i) then { 0 i r := i } else { 0 i r := i } 0 r Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
42 The Example Again (0 i 0 i) (i < 0 0 i) if (0 i) then { 0 i r := i } else { 0 i r := i } 0 r Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
43 The Example Again true (0 i 0 i) (i < 0 0 i) if (0 i) then { 0 i r := i } else { 0 i r := i } 0 r Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
44 Loop Invariants Vesal Vojdani Department of Computer Science University of Tartu Formal Methods (2014) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
45 Warm-Up Consider a simple loop-free program: int succ(int x) { a = x + 1; if (a - 1 == 0) y = 1; else y = a; return y; } Show that y = x + 1 at the return statement. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
46 While Loops Recall the proof rule φ e C φ φ while e do C φ e Given a ψ as post-condition... How can we apply this rule? What is the WP of a while loop? Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
47 Termination? Weakest Liberal Preconditions wp S ψ wp S true wlp S ψ We did not care about this distinction Termination is an outdated concept. ;) Only loops have different definitions. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
48 WP for while loops WP while e do C ψ? Unrolling the loop: F 0 = while e do skip F i = if e then C ; F i 1 else skip WP for exiting the loop after at most i iterations in a state satisfying ψ : L 0 ψ e L i ( e φ) (e WP C L i 1 ) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
49 WLP for while loops WLP while e do C ψ? Unrolling the loop: F 0 = while e do skip F i = if e then C ; F i 1 else skip WLP for if we exit the loop after at most i iterations, the resulting state satisfies ψ : L 0 ψ L i ( e φ) (e WLP C L i 1 ) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
50 WLP for while loops WLP for if we exit the loop after at most i iterations, the resulting state satisfies ψ : L 0 ψ L i ( e φ) (e WLP C L i 1 ) We then define WLP while e do C ψ = i N : L i Not very practical... Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
51 Precondition of a While Loop To push ψ up through while e do C: 1. Guess a potential invariant φ. 2. Make sure φ e = ψ. 3. Compute φ = WLP C φ. 4. Check that φ e = φ. 5. Then, φ is a pre-condition for ψ. φ e C φ φ while e do C φ e Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
52 Proof Tableaux for Loops φ while e do { φ e WLP C φ C φ } φ E ψ Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
53 Exercise 1 int fact(int x) { y = 1; z = 0; while (z!= x) { z = z + 1; y = y * z; } return y; } Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
54 Guessing the invariant Doing a trace: iteration x y z B true true true true true true false i i! i Formulate hypothesis: y = z! Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
55 Proof obligations Want to establish ψ y = x!. 1. Our invariant φ y = z! 2. Check that φ (z x) = ψ. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
56 Proof obligations Want to establish ψ y = x!. 1. Our invariant φ y = z! 2. Check that φ (z x) = ψ. 3. Compute WLP of loop body: Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
57 Proof obligations Want to establish ψ y = x!. 1. Our invariant φ y = z! 2. Check that φ (z x) = ψ. 3. Compute WLP of loop body: φ y (z + 1) = (z + 1)! 4. Check if φ z x = φ. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
58 Proof obligations Want to establish ψ y = x!. 1. Our invariant φ y = z! 2. Check that φ (z x) = ψ. 3. Compute WLP of loop body: φ y (z + 1) = (z + 1)! 4. Check if φ z x = φ. 5. Continue WLP computation with φ. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
59 Exercise 2: Minimal-Sum Section Given an integer array a[0], a[1],..., a[n 1]. A section of a is a continuous piece a[i], a[i + 1],..., a[j] with 0 i j < n. Section sum: S i,j = a[i] + + a[j]. A minimal-sum section is a section a[i],..., a[j] s.t. for any other a[i ],..., a[j ], we have S i,j S i,j. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
60 What to do? Compute the sum of the minimal-sum sections in linear time. Prove that the code is correct! For example... [ 1, 3, 15, 6, 4, 5] is 7 for [ 6, 4, 5]. [ 2, 1, 3, 3] is 3 for [ 2, 1] or [ 3]. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
61 The Program int minsum(int a[]) { k = 1; t = a[0]; s = a[0]; while (k!= n) { t = min(t + a[k], a[k]); s = min(s,t); k = k + 1; } return s; } Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
62 Post-conditions The value s is smaller than the sum of any section. φ 1 = i, j : 0 i j < n s S i,j There is a section whose sum is s φ 2 = i, j : 0 i j < n s = S i,j Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
63 Trying to prove φ 1 Suitable Invariant: φ 1 = i, j : 0 i j < n s S i,j I 1 (s, k) = i, j : 0 i j < k s S i,j Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
64 Trying to prove φ 1 Suitable Invariant: φ 1 = i, j : 0 i j < n s S i,j I 1 (s, k) = i, j : 0 i j < k s S i,j Additional Invariant I 2 (t, k) = i : 0 i < k t S i,k 1 Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
65 The Key Lemma In the end, we have to prove that I 1 (s, k) I 2 (t, k) k n = I 1 (min(s, (min(t + a[k], a[k])), k + 1) I 2 (min(t + a[k], a[k]), k + 1) This will require human intervention: proof-assistants. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
66 Verification Condition Generation Vesal Vojdani Department of Computer Science University of Tartu Formal Methods (2014) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
67 Purpose of this lecture Get an idea of how verification condition generation works. We consider the simplest possible implementation. This is based on early work on ESC/Java. We see some important concepts: collecting semantics constraint systems abstraction Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
68 Quick: What is the Loop Invariant? y := 5 ; x := 0 ; while x 5 do x := x + 1 x = y Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
69 Generating VCs Non-trivial loop-invariants must be supplied, but everything else automatic. Assume program is annotated with Pre- & Post-conditions. For every while-loop, a supposed loop-invariant. How do we check automatically that the implementation satisfies the contract? Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
70 Verification Conditions Consider the triplets: φ C ψ x = x x := x y x + y = x The verification conditions would be φ WP C ψ (x = x ) ((x y) + y = x ) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
71 Asking an SMT Solver We then ask an SMT solver if the VC is true. (x = x ) ((x y) + y = x ) We want the VC to hold for all parameters. Check if the negated formula is satisfiable! Think: searching for a falsifying assignment (failing test case). Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
72 Translation into Flow Graphs Control Flow Graph G = (N, E, s, r) N are program points, and s, r N are start/return nodes. E = N C N are transition, where C is the set of basic statements. x := 5 y := x Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
73 Basic Edges C ::= skip skip x := e assign φ? assume φ! assert Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
74 FOL with linear arithmetic φ ::= e arithmetic φ 1 φ 2 conjunction φ 1 φ 2 disjunction φ 1 φ 2 implication y : φ existential quantification y : φ universal quantification. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
75 Translating If-Statements if e then C 1 else C 2 0 e? e? 1 2 C 1 C 2 3 Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
76 Translating While-Statements while e do C 0 e? 2 C e? 1 Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
77 Program State State σ assigns values to variables: σ: V Z Example: σ 0 = {x 0, y 0} x := 5 y := x Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
78 Program State State σ assigns values to variables: σ: V Z Example: σ 0 = {x 0, y 0} σ 1 = {x 5, y 0} x := 5 y := x Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
79 Program State State σ assigns values to variables: σ: V Z Example: σ 0 = {x 0, y 0} σ 1 = {x 5, y 0} σ 2 = {x 5, y 6} x := 5 y := x Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
80 Evaluating Expressions Given a σ, we evaluate expressions: For σ = {x 5, y 6}, z σ = z x σ = σ x e 1 + e 2 σ = e 1 σ + e 2 σ... x + y σ = x σ + y σ = σ x + σ y = = 11 Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
81 State satisfies a formula Our state is σ: V Z, but φ may contain unbound logical variables x V. A state σ satisfies φ σ φ if φ evaluates to true for some extension of σ: σ : ( v V : σ v = σ v) ( φ σ = true) And a formula φ is satisfiable if σ : σ φ. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
82 A note on triplets Consider the triplet x = x x := x + 1 x = x + 1 where x is a logical variable. When we say that the triplet φ C ψ is valid under partial correctness if σ : σ φ = C σ ψ we assume that σ includes logical variables. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
83 Notation: Updating the State We update the mapping σ: where σ = σ[x z] σ y = { z σ y if y = x otherwise Useful exercise: σ ψ[e/x] σ[x e σ] ψ Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
84 Notation: Updating the State We update the mapping σ: where σ = σ[x z] σ y = { z σ y if y = x otherwise Useful exercise: σ ψ[e/x] σ[x e σ] ψ ψ[e/x] σ = ψ (σ[x e σ]) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
85 Collecting Semantics For every point p N, we want to know The set of states reaching p: S p. If we assume that S s = S 0 = {σ 0 }. σ 0 v = 0 ( v V) x := 5 y := x {σ 0 } {σ 1 } {σ 2 } Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
86 Starting State We need this semantics to validate our WP computation. Therefore, the best choice is S s = V Z, so that only tautologies hold at s. We include all logical variables from assume statements in V. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
87 For a skip edge p skip q S q = S p Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
88 For an assignment edge p q x := e S q = {σ[x e σ] σ S p } Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
89 For an assume edge p q φ? S q = {σ σ S p, φ σ = true} Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
90 For an assert edge p q φ! S q = {σ σ S p, φ σ = true} { σ S p, φ σ = false} Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
91 Quiz: The Error State For any S, what are the results of the edges? false? false! Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
92 Quiz: The Error State For any S, what are the results of the edges? false? false! { } Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
93 Quiz: The Error State For any S, what are the results of the edges? false? false! { } The should pass through other edges (like exceptions / maybe monad) φ = false [x e] = We amend the assume rule... Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
94 Transfer functions skip S = S x := e S = {σ[x e σ] σ S} e? S = {σ σ S p, e σ 0} { S p } e! S = {σ σ S p, e σ 0} { σ S p, e σ = 0} Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
95 Satisfiability for Sets This is lifted as expected: S φ σ S : σ φ As the error state satisfies nothing: φ : φ if S, already S true. (because some assertions may already have failed.) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
96 Example 0 x < 0? 0 x? 1 2 x := x x := x x 0! 4 Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
97 Equation & Constraint Systems Recall G = (N, E, s, r). First we set the starting state: S s = {σ s } (or S s = V Z) And for each point q N: S q = { C S p (p, C, q) E} Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
98 Equation & Constraint Systems Recall G = (N, E, s, r). First we set the starting state: S s = {σ s } (or S s = V Z) And for each point q N: S q = { C S p (p, C, q) E} As a constraint system: S s {σ s } S q C S p for (p, C, q) E Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
99 Constraint System Example Let x p = {σ x σ S p } (and if σ = ). We start with x 0 = x s = Z. x 0 Z x 1 {z z x 0, z < 0} x 2 {z z x 0, 0 z} x 3 { z z x 1 } x 3 {z + 1 z x 2 } x 4 {z z x 3, z 0} { z x 3, z = 0} 0 x < 0? 0 x? 1 2 x := x x := x x 0! 4 Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
100 And Now WP... WP skip ψ = ψ WP x := e ψ = ψ[e/x] WP φ? ψ = φ ψ WP φ! ψ = φ ψ Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
101 Assume versus Assert Definitions: C wp C ψ wlp C ψ φ! φ ψ φ ψ φ? φ ψ φ ψ Our WP C ψ behaves like wp on asserts. However, we will abstract away loops, so in essence this is still partial correctness. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
102 Equation system for WP We now start from the end node r N. Post-conditions are explicitly asserted, so... We start with ψ r = true and for p N: ψ p = {WP c ψ q (p, c, q) E} Alternatively, as a constraint system: ψ r = true ψ p = WP c ψ q for (p, c, q) E Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
103 WP and our Semantics Assume we have computed the initial precondition ψ s starting from the end node ψ r = true. If we start the collecting semantics with S s = {σ σ = ψ s } Then, we expect: S r = true which holds whenever S r. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
104 Quiz: Error State Again Recall our false assume/assert edges: false? false! { } Now what is the WP for these? WP false? ψ WP false! ψ Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
105 Quiz: Error State Again Recall our false assume/assert edges: false? false! { } Now what is the WP for these? WP false? ψ true WP false! ψ false Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
106 Again this example: 0 x < 0? 0 x? 1 2 x := x x := x x 0! 4 Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
107 Now recall this example... y := 5 ; x := 0 ; while x 5 do x := x + 1 ; x = y! Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
108 We could compute this... 0 y := 5 ; x := 0 1 x = 5? x = y! 3 4 x := x + 1 x 5? 2 Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
109 VCG: Abstraction of Loops Vesal Vojdani Department of Computer Science University of Tartu Formal Methods (2014) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
110 WP computation was stuck in this loop 0 y := 5 ; x := 0 1 x = 5? x = y! 3 4 x := x + 1 x 5? 2 Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
111 Havoc (wrong!) Concrete semantics: havoc x S = {σ[x z] σ S, z Z} WP for havoc: WP havoc x ψ = x : ψ Practically, all information about x is lost, except indirect relations remain: WP havoc x (y = x x = z) = (y = z) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
112 Havoc (for post-conditions!) Concrete semantics: havoc x S = {σ[x z] σ S, z Z} WP for havoc: WP havoc x ψ = x : ψ Practically, all information about x is lost, except indirect relations remain (after the assignment): WP havoc x (y = x x = z) = (y = z) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
113 Pre-Condition of Havoc Concrete semantics: havoc x S = {σ[x z] σ S, z Z} WP for havoc: WP havoc x ψ = x : ψ We need ψ to hold for all values of x. Usually, we have assumes after havoc, so a typical example is WP havoc x ((y = x) (x = z)) = (y = z) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
114 Pre-Condition of Havoc Concrete semantics: havoc x S = {σ[x z] σ S, z Z} WP for havoc: WP havoc x ψ = ψ[x /x] x is fresh! We need ψ to hold for all values of x. Usually, we have assumes after havoc, so a typical example is WP havoc x ((y = x) (x = z)) = (y = z) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
115 A simple assumption We should havoc all variables that are assigned to in the loop body. For simplicity, we assume this is only x. (You may think of x as a vector.) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
116 Normal While Loop 0 e? 2 C e? 1 Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
117 Abstraction using invariant φ 0 φ! ; havoc x ; φ? 0 e? 2 e? false? 1 2 C ; φ! Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
118 Why can we do this? The construction guarantees that if we have S 2 S 2 S 2 where S i are the sets computed for the original while loop. Note: it follows very closely the proof rules of Hoare logic. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
119 Now we really can compute a VC 0 y := 5 ; x := 0 1 havoc x 1 x = 5? 3 x = y! 4 x 5? false? 2 x := x Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
120 What happened? Well, there was no invariant to check. That s good because the invariant was trivial. The homework requires making this construction with an invariant. Just a note on procedure, and then we prove the soundness of the construction. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
121 Procedure Calls Given a function P with parameter p and result r and contract φ P ψ We produce the following translation for a call x = P(e). p := e φ! ψ? x := r Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
122 Soundness of the transformation C 0 1 e? e? 2 A 0 φ! ; havoc x ; φ? e? 2 e? false? 1 B C ; φ! Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
123 Proof Plan 1. Write down constraint systems S and S. 2. Separate assertions into the conditions they impose constraint system for values 3. Show that the value system satisfies the constraints of S. 4. This implies that any solution of S is greater than the least solution of S. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
124 Constraint System S S 0 S S 0 C S 1 S 1 e? S 0 S 2 e? S 0 C 0 e? e? 2 1 Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
125 Constraint System S S A S S 0 φ? {σ[x z] z Z, σ φ! S A} S 1 e? S 0 S B φ! ( C S 1) S 2 e? S 0 { S B} A 0 φ! ; havoc x ; φ? e? e? false? 2 1 B C ; φ! Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
126 Splitting S based on S 2 We can be sure S 2 if we have S φ C S 1 φ Letting S x = {σ[x z] z Z, σ S}, the following constraints remain: S 0 φ? S x S 1 e? S 0 S 2 e? S 0 Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
127 Splitting S based on S 2 We can be sure S 2 if we have S φ C S 1 φ Letting S x = {σ[x z] z Z, σ S}, we obtain the following solution: S 0 = {σ S x σ φ} S 1 = {σ S x σ φ e} S 2 = {σ S x σ φ e} Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
128 Solution to original system? Given the solution and conditions: S 0 = {σ S x σ φ} S 1 = {σ S x σ φ e} S 2 = {σ S x σ φ e} S φ C S 1 φ We check if the original constraints are satisfied: S 0 S S 0 C S 1 S 1 e? S 0 S 2 e? S 0 Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
129 What did we just do? We had two systems: X F(X) X F (X) We showed that for any Y Y F (Y) = Y F(Y) What did we conclude? Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
130 Data Flow Analysis Vesal Vojdani Department of Computer Science University of Tartu Formal Methods (2014) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
131 Data Flow Analysis We now consider how to check assertions using data flow analysis. Before we do that, we must to understand the basics of classical data flow analysis frameworks. We need to reason about soundness. Statements about programs are ordered... Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
132 Partial Orders Definition A set D together with a relation is a partial order if for all a, b, c D, a a a b b a = a = b a b b c = a c reflexivity anti-symmetry transitivity Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
133 Examples 1. D = 2 {a,b,c} with the relation 2. Z with the relation = 3. Z with the relation 4. Z = Z { } with the ordering: x y (x = ) (x = y) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
134 Facts about the program Our domain elements represent propositions about the program. Let p = x denote x holds whenever execution reaches program point p. We order these propositions such that x y whenever (p = x) = (p = y) Consider examples: The set of possibly live variables. The set of definitely initialized variables. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
135 Combining information Assume there are two paths to reach p (true-branch and false-branch). If we have x along one path and y along the other, how can we combine this information? x y We want something that is true of both paths, and as precise as possible. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
136 Least Upper Bounds d D is called an upper bound for X D if x d for all x X d is called a least upper bound if 1. d is an upper bound and 2. d y for every upper bound y of X. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
137 Do least upper bounds always exist? h i e f g a b c Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
138 Do least upper bounds always exist? h i e f g a b c Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
139 Do least upper bounds always exist? h i e f g a b c Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
140 Do least upper bounds always exist? h i e f g a b c Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
141 Complete Lattice Definition A complete lattice D is a partial ordering where every subset X D has a least upper bound X D. Every complete lattice has a least element = D; a greatest element = D D. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
142 Which are complete lattices? 1. D = 2 {a,b,c} 2. D = Z with =. 3. D = Z with. 4. D = Z. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
143 Which are complete lattices? 1. D = 2 {a,b,c} 2. D = Z with =. 3. D = Z with. 4. D = Z. 5. Z = Z {, }. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
144 Proof demo: Greatest Lower Bounds Recall the definition A complete lattice D is a partial ordering where every subset X D has a least upper bound X D. Theorem If D is a complete lattice, then every subset X D has a greatest lower bound X. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
145 Proof L = {l x X : l x}. Let g = L. (Least upper bound of the lower bounds.) We show that g = X. 1. Show that g is a lower bound of X. 2. Show that g is the greatest lower bound. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
146 Solving constraint systems Recall the concrete semantics: S q c S p for (p, c, q) E In general: x i f i (x 1,..., x n ) We rewrite multiple constraints: x d 1 x d k x {d 1,..., d k } Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
147 So how to do it? In order to solve: x i f i (x 1,..., x n ) We need f i to be monotonic. A mapping f is monotonic if a b = f(a) f(b) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
148 Monotonicity A mapping f is monotonic if a b = f(a) f(b) Which of the following is not monotonic? inc x = x + 1 dec x = x 1 Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
149 Monotonicity A mapping f is monotonic if a b = f(a) f(b) Which of the following is not monotonic? inc x = x + 1 dec x = x 1 top x = bot x = Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
150 Monotonicity A mapping f is monotonic if a b = f(a) f(b) Which of the following is not monotonic? inc x = x + 1 dec x = x 1 top x = bot x = id x = x inv x = x Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
151 Vector function We want to solve: x i f i (x 1,..., x n ) Construct vector function F: D n D n F(x 1,..., x n ) = (y 1,..., y n ) where y i = f i (x 1,..., x n ) If f i are monotonic, so is F. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
152 Kleene iteration Successively iterate from :, F( ), F 2 ( ),... Stop if we reach some X = F n ( ) with F(X) = X Will this terminate? Is this the least solution? Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
153 Simple Example For D = 2 {a,b,c} x 1 {a} x 3 x 2 x 3 {a, b} x 3 x 1 {c} The Iteration x 1 x 2 x Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
154 Simple Example For D = 2 {a,b,c} x 1 {a} x 3 x 2 x 3 {a, b} x 3 x 1 {c} The Iteration x 1 {a} x 2 x 3 {c} Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
155 Simple Example For D = 2 {a,b,c} x 1 {a} x 3 x 2 x 3 {a, b} x 3 x 1 {c} The Iteration x 1 {a} {a, c} x 2 x 3 {c} {a, c} Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
156 Simple Example For D = 2 {a,b,c} x 1 {a} x 3 x 2 x 3 {a, b} x 3 x 1 {c} The Iteration x 1 {a} {a, c} {a, c} x 2 {a} x 3 {c} {a, c} {a, c} Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
157 Simple Example For D = 2 {a,b,c} x 1 {a} x 3 x 2 x 3 {a, b} x 3 x 1 {c} The Iteration x 1 {a} {a, c} {a, c} x 2 {a} x 3 {c} {a, c} {a, c} Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
158 Why Kleene iteration works 1., F( ), F 2 ( ),... is an ascending chain F( ) F 2 ( ) 2. If F k ( ) = F k+1 ( ), it is the least solution. 3. If all ascending chains in D are finite, Kleene iteration terminates. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
159 Discussion What if D does contain infinite ascending chains? In particular, our concrete semantics was defined as the set of states with σ V N. How do we know there aren t better solutions to the constraint system? x = f(x) x f(x) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
160 Answer to the first question Theorem (Knaster-Tarski) Assume D is a complete lattice. Then every monotonic function f: D D has a least fixpoint d 0 D where d 0 = P P = {d D d f(d)} 1. Show that d 0 P. 2. Show that d 0 is a fixpoint. 3. Show that d 0 is the least fixpoint. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
161 Answer to the second question Could there be better solutions to the constraint system than the least fixpoint? According to the theorem: d 0 = {d D d f(d)} Thus, d 0 is a lower bound for all solutions to the constraint system d f(d). Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
162 Chaotic iteration 1. Set all x i to and W = {1,..., n}. 2. Take some i W out of W. (if W =, exit). 3. Compute n := f i (x 1,..., x n ). 4. If x i n, goto Set x i := x i n and reset W := {1,..., n}. 6. Goto 2. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
163 Data flow versus paths We want to verify that whenever execution reaches program point p, a certain assertion holds. We need to check every path leading to p. Then: Why are we solving data flow constraint systems?? Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
164 Path Semantics We define a path π inductively: π = ɛ π = π e empty path where e E If π is a path from p to q, we write π: p q. We define the path semantics: ɛ S = S π(p, c, q) S = c ( π S) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
165 Merge Over All Paths For a complete lattice D, we solved x s d s x q c x p (p, c, q) E But we are really interested in: y p = { π d s π: s p} Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
166 Example: Merge Over All Paths skip 0 skip 1 2 x := 4 3 x := 4 y := x 2 y = 16! 4 5 Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
167 When do solutions coincide? For our collecting semantics, they do. All functions c are distributive. In reality, we compute an abstract semantics. x s d s x q c x p (p, c, q) E Transfer functions c : D D are monotonic. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
168 Soundness of LFP Solutions Theorem (Kam, Ullman, 1975) Let x i satisfy the following constraint system: x s d s x q c x p (p, c, q) E where c are monotonic. Then, for every p N, we have x p { π d s π: s p} Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
169 Proof We need to show that for each π: s p: x p π d s By induction on the length of π (assume the above holds for all paths of length n to any node). Base case. There is only one zero-length path: π = ɛ. We have x s ɛ d s from the first constraint. Inductive step: Let π = π (p, c, q). We have x p π d s from the inductive hypothesis. We need x q π d s = c ( π d s ). From monotonicity: x q c x p c ( π d s ). Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
170 On Distributivity A function f: D 1 D 2 is distributive if for all X D 1 : ( ) f X = {f x x X} It is strict if f = It is totally distributive if both distributive and strict (distributes also ). Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
171 Why these distinctions? Many useful analyses are distributive, but... we generally do not have strict transfer functions. Instead, we assume each node v is reachable from the start node. Under these assumptions, distributivity suffices for our coinidence theorem. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
172 Intraprocedural Coincidence Theorem (Kildall, 1972) Let x i satisfy the following constraint system: x s d s x q c x p (p, c, q) E where c are distributive. Then, for every p N, we have x p = { π d s π: s p} Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
173 Proof I Note that any distributive function is also monotonic. Simple proof using: x y x y = y Thus, we only need to show this direction: x p { π d s π: s p} For this, we show that the MOP solution satisfies our constraint system. (WHY?) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
174 Proof II We show for an edge (p, c, q): x q c x p We compute: x q = { π d s π: s q} { π d s π: s p q} = { c ( π d s ) π: s p} ( ) = c { π d s π: s p} = c x p Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
175 Implementing a constraint solver Given the definitions: a s : D value at program start s : D D abstract semantics Solve the following system: x q d s q entry point x q c x p (p, c, q) edge Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
176 Representation of Right-Hand Sides For each variable x V, we have a single constraint f x. Given the sets V : Constraint Variables (Unknowns) D: The abstract value domain. The type of right hand sides are f x : (V D) D Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
177 The example encoded Mathematical formulation: x 1 {a} x 3 x 2 x 3 {a, b} x 3 x 1 {c} Functional encoding: f x1 = λσ. {a} σ x 3 f x2 = λσ. σ x 3 {a, b} f x3 = λσ. σ x 1 {c} Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
178 Encoding in Haskell data V = X1 X2 X3 deriving (Eq,Show) class FSet v where vars :: [v] instance FSet V where vars = [X1,X2,X3] f X1 = \σ S.fromList [ a ] (σ X3) f X2 = \σ (σ X3) S.fromList [ a, b ] f X3 = \σ (σ X1) S.fromList [ c ] Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
179 Assignments and Solutions Given a variable assignment σ: V D, we can evaluate a right-hand-side f σ D. An assignment σ satisfies a constraint x f x iff σ x f x σ When σ satisfies all constrains, it is a solution. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
180 Haskell Code: Check Solution type RHS v d = (v d) d type Sys v d = v RHS v d type Sol v d = v d verify σ f = all verifyvar vars where verifyvar v = σ v f v σ Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
181 Kleene Iteration We iterate a monotonic function starting from : f f (f ) f i Until (hopefully) we reach an i, such that f i f i 1 Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
182 Haskell Code: Domains class Domain t where ( ) :: t t Bool ( ) :: t t t bot :: t lfp :: Domain d => (d d) d lfp f = stable (iterate f bot) stable (x:fx:tl) fx x = x otherwise = stable (fx:tl) matt.might.net/articles/partial-orders/ iterate f x = x : iterate f ( f x) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
183 Haskell Code: Vector Function instance (FSet v, Domain d) => Domain (v d) where f g = all (\v f v g v) vars f g = \v f v g v bot = \v bot solve f = lfp (flip f) f: V (V D) D flip f: (V D) (V D) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
184 Testing the Simple Solver instance Ord e => Domain (Set e) where x y = x y x y = x y bot = empty f X1 = \σ S.fromList [ a ] (σ X3) f X2 = \σ (σ X3) S.fromList [ a, b ] f X3 = \σ (σ X1) S.fromList [ c ] *Simple> solve f X1 fromlist "ac" X2 fromlist "a" X3 fromlist "ac" Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
185 Assertion Checking with Static Analysis Vesal Vojdani Department of Computer Science University of Tartu Formal Methods (2014) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
186 Assertion Checking Track values of variables. Combine with WP computation. Infer invariants for loops. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
187 Value Domains Characterize the possible values of variables whenever we reach program point p. A non-relational value domain: D = V D Z We consider two simple value domains: 1. Kildall s constant propagation domain. 2. The Interval Domain. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
188 Non-relational Domains For a complete lattice D and finite set V, the set of functions D V with the point-wise ordering f 1 f 2 v V : f 1 (v) f 2 (v) is also a complete lattice. For example: D = V 2 Z. Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
189 Abstract Evaluation Just like for concrete state σ V Z: z σ = z x σ = σ x e 1 + e 2 σ = e 1 σ + e 2 σ Now, we need abstract operators such that for d D = V D Z, we evaluate: z d = z x d = d x e 1 + e 2 d = e 1 d + e 2 d Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
190 What the domain must supply 1. Lattice operations. 2. Lifting of constants: 3. Abstract operations: z Z : z D Z z 1, z 2 D Z : z 1 + z 2 D Z (not just for +; also unary, comparisons, logical, etc.) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
191 Kildall s Domain 1. Lattice is the flat lattice. 2. Constants are already elements of D Z : z = z 3. Operators are essentially lifted: if a = or b = a + b = if a = or b = a + b otherwise (More precise, e.g., for multiplication?) Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
192 Interval Domain 1. Lattice is Z Z with l 1, u 1 l 2, u 2 if l 2 l 1 u 1 u 2 2. Constants are singleton intervals: z = z, z 3. Operators are generally defined as: l 1, u 1 l 2, u 2 = l, u where l = min {a b a {l 1, u 1 }, b {l 2, u 2 }} u = max{a b a {l 1, u 1 }, b {l 2, u 2 }} Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
193 The Analysis We define abstract transfer functions. The simple ones: skip d = d x := e d = d[x e d] Much like the concrete semantics: skip S = S x := e S = {σ[x e σ] σ S} Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
194 The Bottom Value The bottom element is the mapping d v = ( v V) As soon as v with d v =, we would set all variables to. The bottom value then denotes non-reachability. All transfer functions would strictly let pass through. Why allow in the value domains at all? Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
195 Assume edges The concrete semantics: e? S = {σ σ S p, e σ 0} { S p } We will handle errors separately. Abstract value sets: { e? if e d = 0 d = d d t otherwise where d t = minimal elems {d e d 0} Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
196 Example 1: Dead Code 0 x := 5 1 x = 5? x 5? 2 3 y := 9 y := 6 4 y = 9! 5 Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
197 Example 2: Restricting Values 0 x = 5? x 5? 1 2 x := x + 1 x := 6 3 x = 6! 4 Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
198 Correctness We have a monotonic concretization function γ. For the value domains γ: D Z 2 Z. if a = γ z = Z if a = {z} otherwise For the variable assignments: { if v : d v = γ d = {ρ v : ρ v γ (d v)} otherwise Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
199 Correctness condition All our transfer functions need to satisfy: c (γ d) γ ( c d) Then, then the least solutions also satisfy: S p γ x p Because if we have f(γ x) γ(f x) and d = f d, then f(γ d) γ(f d) = γ d Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
200 Assert edges Their effect on values is like assume: e! S = {σ σ S p, e σ 0} { σ S p, e σ = 0} So how to check assertions? (next slide) Let x p be the value analysis: x 0 d 0 x q c x p for (p, c, q) E Vesal Vojdani (University of Tartu) Formal Methods in SW Engineering Fall / 187
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 informationHoare Logic I. Introduction to Deductive Program Verification. Simple Imperative Programming Language. Hoare Logic. Meaning of Hoare Triples
Hoare Logic I Introduction to Deductive Program Verification Işıl Dillig Program Spec Deductive verifier FOL formula Theorem prover valid contingent Example specs: safety (no crashes), absence of arithmetic
More informationDeductive Verification
Deductive Verification Mooly Sagiv Slides from Zvonimir Rakamaric First-Order Logic A formal notation for mathematics, with expressions involving Propositional symbols Predicates Functions and constant
More informationAxiomatic Semantics: Verification Conditions. Review of Soundness and Completeness of Axiomatic Semantics. Announcements
Axiomatic Semantics: Verification Conditions Meeting 12, CSCI 5535, Spring 2009 Announcements Homework 4 is due tonight Wed forum: papers on automated testing using symbolic execution 2 Questions? Review
More informationLecture Notes: Axiomatic Semantics and Hoare-style Verification
Lecture Notes: Axiomatic Semantics and Hoare-style Verification 17-355/17-665/17-819O: Program Analysis (Spring 2018) Claire Le Goues and Jonathan Aldrich clegoues@cs.cmu.edu, aldrich@cs.cmu.edu It has
More informationProgram Analysis Part I : Sequential Programs
Program Analysis Part I : Sequential Programs IN5170/IN9170 Models of concurrency Program Analysis, lecture 5 Fall 2018 26. 9. 2018 2 / 44 Program correctness Is my program correct? Central question for
More informationHoare Calculus and Predicate Transformers
Hoare Calculus and Predicate Transformers Wolfgang Schreiner Wolfgang.Schreiner@risc.uni-linz.ac.at Research Institute for Symbolic Computation (RISC) Johannes Kepler University, Linz, Austria http://www.risc.uni-linz.ac.at
More informationReasoning About Imperative Programs. COS 441 Slides 10b
Reasoning About Imperative Programs COS 441 Slides 10b Last time Hoare Logic: { P } C { Q } Agenda If P is true in the initial state s. And C in state s evaluates to s. Then Q must be true in s. Program
More informationHoare Logic and Model Checking
Hoare Logic and Model Checking Kasper Svendsen University of Cambridge CST Part II 2016/17 Acknowledgement: slides heavily based on previous versions by Mike Gordon and Alan Mycroft Introduction In the
More informationFloyd-Hoare Style Program Verification
Floyd-Hoare Style Program Verification Deepak D Souza Department of Computer Science and Automation Indian Institute of Science, Bangalore. 9 Feb 2017 Outline of this talk 1 Overview 2 Hoare Triples 3
More informationAxiomatic Semantics: Verification Conditions. Review of Soundness of Axiomatic Semantics. Questions? Announcements
Axiomatic Semantics: Verification Conditions Meeting 18, CSCI 5535, Spring 2010 Announcements Homework 6 is due tonight Today s forum: papers on automated testing using symbolic execution Anyone looking
More informationClassical Program Logics: Hoare Logic, Weakest Liberal Preconditions
Chapter 1 Classical Program Logics: Hoare Logic, Weakest Liberal Preconditions 1.1 The IMP Language IMP is a programming language with an extensible syntax that was developed in the late 1960s. We will
More informationAxiomatic Semantics. Stansifer Ch 2.4, Ch. 9 Winskel Ch.6 Slonneger and Kurtz Ch. 11 CSE
Axiomatic Semantics Stansifer Ch 2.4, Ch. 9 Winskel Ch.6 Slonneger and Kurtz Ch. 11 CSE 6341 1 Outline Introduction What are axiomatic semantics? First-order logic & assertions about states Results (triples)
More informationAxiomatic Semantics. Lecture 9 CS 565 2/12/08
Axiomatic Semantics Lecture 9 CS 565 2/12/08 Axiomatic Semantics Operational semantics describes the meaning of programs in terms of the execution steps taken by an abstract machine Denotational semantics
More informationAxiomatic semantics. Semantics and Application to Program Verification. Antoine Miné. École normale supérieure, Paris year
Axiomatic semantics Semantics and Application to Program Verification Antoine Miné École normale supérieure, Paris year 2015 2016 Course 6 18 March 2016 Course 6 Axiomatic semantics Antoine Miné p. 1 /
More informationCSC 7101: Programming Language Structures 1. Axiomatic Semantics. Stansifer Ch 2.4, Ch. 9 Winskel Ch.6 Slonneger and Kurtz Ch. 11.
Axiomatic Semantics Stansifer Ch 2.4, Ch. 9 Winskel Ch.6 Slonneger and Kurtz Ch. 11 1 Overview We ll develop proof rules, such as: { I b } S { I } { I } while b do S end { I b } That allow us to verify
More informationA Short Introduction to Hoare Logic
A Short Introduction to Hoare Logic Supratik Chakraborty I.I.T. Bombay June 23, 2008 Supratik Chakraborty (I.I.T. Bombay) A Short Introduction to Hoare Logic June 23, 2008 1 / 34 Motivation Assertion checking
More informationFirst-Order Logic First-Order Theories. Roopsha Samanta. Partly based on slides by Aaron Bradley and Isil Dillig
First-Order Logic First-Order Theories Roopsha Samanta Partly based on slides by Aaron Bradley and Isil Dillig Roadmap Review: propositional logic Syntax and semantics of first-order logic (FOL) Semantic
More informationStatic 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 informationDesign of Distributed Systems Melinda Tóth, Zoltán Horváth
Design of Distributed Systems Melinda Tóth, Zoltán Horváth Design of Distributed Systems Melinda Tóth, Zoltán Horváth Publication date 2014 Copyright 2014 Melinda Tóth, Zoltán Horváth Supported by TÁMOP-412A/1-11/1-2011-0052
More informationStatic 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 informationProgram verification using Hoare Logic¹
Program verification using Hoare Logic¹ Automated Reasoning - Guest Lecture Petros Papapanagiotou Part 2 of 2 ¹Contains material from Mike Gordon s slides: Previously on Hoare Logic A simple while language
More informationTopics in Model-Based Reasoning
Towards Integration of Proving and Solving Dipartimento di Informatica Università degli Studi di Verona Verona, Italy March, 2014 Automated reasoning Artificial Intelligence Automated Reasoning Computational
More informationHoare 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 informationSoundness and Completeness of Axiomatic Semantics
#1 Soundness and Completeness of Axiomatic Semantics #2 One-Slide Summary A system of axiomatic semantics is sound if everything we can prove is also true: if ` { A } c { B } then ² { A } c { B } We prove
More informationFormal Reasoning CSE 331. Lecture 2 Formal Reasoning. Announcements. Formalization and Reasoning. Software Design and Implementation
CSE 331 Software Design and Implementation Lecture 2 Formal Reasoning Announcements Homework 0 due Friday at 5 PM Heads up: no late days for this one! Homework 1 due Wednesday at 11 PM Using program logic
More informationCS422 - Programming Language Design
1 CS422 - Programming Language Design Denotational Semantics Grigore Roşu Department of Computer Science University of Illinois at Urbana-Champaign 2 Denotational semantics, also known as fix-point semantics,
More informationHoare Logic: Reasoning About Imperative Programs
Hoare Logic: Reasoning About Imperative Programs COMP1600 / COMP6260 Dirk Pattinson Australian National University Semester 2, 2018 Programming Paradigms Functional. (Haskell, SML, OCaml,... ) main paradigm:
More informationThe Assignment Axiom (Hoare)
The Assignment Axiom (Hoare) Syntax: V := E Semantics: value of V in final state is value of E in initial state Example: X:=X+ (adds one to the value of the variable X) The Assignment Axiom {Q[E/V ]} V
More informationLecture Notes on Invariants for Arbitrary Loops
15-414: Bug Catching: Automated Program Verification Lecture Notes on Invariants for Arbitrary Loops Matt Fredrikson Ruben Martins Carnegie Mellon University Lecture 5 1 Introduction The previous lecture
More informationLogical 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 informationSpring 2016 Program Analysis and Verification. Lecture 3: Axiomatic Semantics I. Roman Manevich Ben-Gurion University
Spring 2016 Program Analysis and Verification Lecture 3: Axiomatic Semantics I Roman Manevich Ben-Gurion University Warm-up exercises 1. Define program state: 2. Define structural semantics configurations:
More informationIntroduction to Axiomatic Semantics
#1 Introduction to Axiomatic Semantics #2 How s The Homework Going? Remember that you can t just define a meaning function in terms of itself you must use some fixed point machinery. #3 Observations A
More informationDecision Procedures. Jochen Hoenicke. Software Engineering Albert-Ludwigs-University Freiburg. Winter Term 2016/17
Decision Procedures Jochen Hoenicke Software Engineering Albert-Ludwigs-University Freiburg Winter Term 2016/17 Jochen Hoenicke (Software Engineering) Decision Procedures Winter Term 2016/17 1 / 436 Program
More informationCOP4020 Programming Languages. Introduction to Axiomatic Semantics Prof. Robert van Engelen
COP4020 Programming Languages Introduction to Axiomatic Semantics Prof. Robert van Engelen Assertions and Preconditions Assertions are used by programmers to verify run-time execution An assertion is a
More informationConstraint Solving for Program Verification: Theory and Practice by Example
Constraint Solving for Program Verification: Theory and Practice by Example Andrey Rybalchenko Technische Universität München Abstract. Program verification relies on the construction of auxiliary assertions
More informationConstraint Solving for Program Verification: Theory and Practice by Example
Constraint Solving for Program Verification: Theory and Practice by Example Andrey Rybalchenko Technische Universität München Abstract. Program verification relies on the construction of auxiliary assertions
More informationLecture 13: Soundness, Completeness and Compactness
Discrete Mathematics (II) Spring 2017 Lecture 13: Soundness, Completeness and Compactness Lecturer: Yi Li 1 Overview In this lecture, we will prvoe the soundness and completeness of tableau proof system,
More informationCMSC 631 Program Analysis and Understanding Fall Abstract Interpretation
Program Analysis and Understanding Fall 2017 Abstract Interpretation Based on lectures by David Schmidt, Alex Aiken, Tom Ball, and Cousot & Cousot What is an Abstraction? A property from some domain Blue
More informationAbstract Interpretation II
Abstract Interpretation II Semantics and Application to Program Verification Antoine Miné École normale supérieure, Paris year 2015 2016 Course 11 13 May 2016 Course 11 Abstract Interpretation II Antoine
More informationCS156: The Calculus of Computation Zohar Manna Autumn 2008
Page 3 of 52 Page 4 of 52 CS156: The Calculus of Computation Zohar Manna Autumn 2008 Lecturer: Zohar Manna (manna@cs.stanford.edu) Office Hours: MW 12:30-1:00 at Gates 481 TAs: Boyu Wang (wangboyu@stanford.edu)
More informationDynamic Noninterference Analysis Using Context Sensitive Static Analyses. Gurvan Le Guernic July 14, 2007
Dynamic Noninterference Analysis Using Context Sensitive Static Analyses Gurvan Le Guernic July 14, 2007 1 Abstract This report proposes a dynamic noninterference analysis for sequential programs. This
More informationLearning Goals of CS245 Logic and Computation
Learning Goals of CS245 Logic and Computation Alice Gao April 27, 2018 Contents 1 Propositional Logic 2 2 Predicate Logic 4 3 Program Verification 6 4 Undecidability 7 1 1 Propositional Logic Introduction
More informationTemporal logics and explicit-state model checking. Pierre Wolper Université de Liège
Temporal logics and explicit-state model checking Pierre Wolper Université de Liège 1 Topics to be covered Introducing explicit-state model checking Finite automata on infinite words Temporal Logics and
More informationHoare Logic (I): Axiomatic Semantics and Program Correctness
Hoare Logic (I): Axiomatic Semantics and Program Correctness (Based on [Apt and Olderog 1991; Gries 1981; Hoare 1969; Kleymann 1999; Sethi 199]) Yih-Kuen Tsay Dept. of Information Management National Taiwan
More informationSMT BASICS WS 2017/2018 ( ) LOGIC SATISFIABILITY MODULO THEORIES. Institute for Formal Models and Verification Johannes Kepler Universität Linz
LOGIC SATISFIABILITY MODULO THEORIES SMT BASICS WS 2017/2018 (342.208) Armin Biere Martina Seidl biere@jku.at martina.seidl@jku.at Institute for Formal Models and Verification Johannes Kepler Universität
More informationProof Rules for Correctness Triples
Proof Rules for Correctness Triples CS 536: Science of Programming, Fall 2018 A. Why? We can t generally prove that correctness triples are valid using truth tables. We need proof axioms for atomic statements
More informationStatic Program Analysis
Static Program Analysis Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ss-18/spa/ Recap: Interprocedural Dataflow Analysis Outline of
More informationEqualities 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 informationSpring 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 informationTemporal Logic - Soundness and Completeness of L
Temporal Logic - Soundness and Completeness of L CS402, Spring 2018 Soundness Theorem 1 (14.12) Let A be an LTL formula. If L A, then A. Proof. We need to prove the axioms and two inference rules to be
More informationLecture 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 informationIn this episode of The Verification Corner, Rustan Leino talks about Loop Invariants. He gives a brief summary of the theoretical foundations and
In this episode of The Verification Corner, Rustan Leino talks about Loop Invariants. He gives a brief summary of the theoretical foundations and shows how a program can sometimes be systematically constructed
More informationChapter 3 Deterministic planning
Chapter 3 Deterministic planning In this chapter we describe a number of algorithms for solving the historically most important and most basic type of planning problem. Two rather strong simplifying assumptions
More informationChapter 4: Computation tree logic
INFOF412 Formal verification of computer systems Chapter 4: Computation tree logic Mickael Randour Formal Methods and Verification group Computer Science Department, ULB March 2017 1 CTL: a specification
More informationFormal Modeling with Propositional Logic
Formal Modeling with Propositional Logic Assaf Kfoury February 6, 2017 (last modified: September 3, 2018) Contents 1 The Pigeon Hole Principle 2 2 Graph Problems 3 2.1 Paths in Directed Graphs..................................
More informationCSE 331 Winter 2018 Reasoning About Code I
CSE 331 Winter 2018 Reasoning About Code I Notes by Krysta Yousoufian Original lectures by Hal Perkins Additional contributions from Michael Ernst, David Notkin, and Dan Grossman These notes cover most
More informationProgram Analysis. Lecture 5. Rayna Dimitrova WS 2016/2017
Program Analysis Lecture 5 Rayna Dimitrova WS 2016/2017 2/21 Recap: Constant propagation analysis Goal: For each program point, determine whether a variale has a constant value whenever an execution reaches
More informationProving Inter-Program Properties
Unité Mixte de Recherche 5104 CNRS - INPG - UJF Centre Equation 2, avenue de VIGNATE F-38610 GIERES tel : +33 456 52 03 40 fax : +33 456 52 03 50 http://www-verimag.imag.fr Proving Inter-Program Properties
More informationLecture Notes on Inductive Definitions
Lecture Notes on Inductive Definitions 15-312: Foundations of Programming Languages Frank Pfenning Lecture 2 August 28, 2003 These supplementary notes review the notion of an inductive definition and give
More informationModel Checking & Program Analysis
Model Checking & Program Analysis Markus Müller-Olm Dortmund University Overview Introduction Model Checking Flow Analysis Some Links between MC and FA Conclusion Apology for not giving proper credit to
More informationAutomata-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 informationSemantics and Verification of Software
Semantics and Verification of Software Thomas Noll Software Modeling and Verification Group RWTH Aachen University http://moves.rwth-aachen.de/teaching/ws-1718/sv-sw/ Recap: The Denotational Approach Semantics
More informationThe non-logical symbols determine a specific F OL language and consists of the following sets. Σ = {Σ n } n<ω
1 Preliminaries In this chapter we first give a summary of the basic notations, terminology and results which will be used in this thesis. The treatment here is reduced to a list of definitions. For the
More informationSolving Constrained Horn Clauses using Interpolation
Solving Constrained Horn Clauses using Interpolation MSR-TR-2013-6 Kenneth L. McMillan Micrsoft Research Andrey Rybalchenko Technische Universität München Abstract We present an interpolation-based method
More informationn Empty Set:, or { }, subset of all sets n Cardinality: V = {a, e, i, o, u}, so V = 5 n Subset: A B, all elements in A are in B
Discrete Math Review Discrete Math Review (Rosen, Chapter 1.1 1.7, 5.5) TOPICS Sets and Functions Propositional and Predicate Logic Logical Operators and Truth Tables Logical Equivalences and Inference
More informationLecture Notes on Software Model Checking
15-414: Bug Catching: Automated Program Verification Lecture Notes on Software Model Checking Matt Fredrikson André Platzer Carnegie Mellon University Lecture 19 1 Introduction So far we ve focused on
More informationSoftware Engineering
Software Engineering Lecture 07: Design by Contract Peter Thiemann University of Freiburg, Germany 02.06.2014 Table of Contents Design by Contract Contracts for Procedural Programs Contracts for Object-Oriented
More informationUnifying Theories of Programming
1&2 Unifying Theories of Programming Unifying Theories of Programming 3&4 Theories Unifying Theories of Programming designs predicates relations reactive CSP processes Jim Woodcock University of York May
More informationSpring 2015 Program Analysis and Verification. Lecture 4: Axiomatic Semantics I. Roman Manevich Ben-Gurion University
Spring 2015 Program Analysis and Verification Lecture 4: Axiomatic Semantics I Roman Manevich Ben-Gurion University Agenda Basic concepts of correctness Axiomatic semantics (pages 175-183) Hoare Logic
More informationSemantics and Verification of Software
Semantics and Verification of Software Thomas Noll Software Modeling and Verification Group RWTH Aachen University http://moves.rwth-aachen.de/teaching/ss-15/sv-sw/ The Denotational Approach Denotational
More informationThis is logically equivalent to the conjunction of the positive assertion Minimal Arithmetic and Representability
16.2. MINIMAL ARITHMETIC AND REPRESENTABILITY 207 If T is a consistent theory in the language of arithmetic, we say a set S is defined in T by D(x) if for all n, if n is in S, then D(n) is a theorem of
More informationDeductive Systems. Lecture - 3
Deductive Systems Lecture - 3 Axiomatic System Axiomatic System (AS) for PL AS is based on the set of only three axioms and one rule of deduction. It is minimal in structure but as powerful as the truth
More informationSpring 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 informationSoftwaretechnik. Lecture 13: Design by Contract. Peter Thiemann University of Freiburg, Germany
Softwaretechnik Lecture 13: Design by Contract Peter Thiemann University of Freiburg, Germany 25.06.2012 Table of Contents Design by Contract Contracts for Procedural Programs Contracts for Object-Oriented
More informationSoftwaretechnik. Lecture 13: Design by Contract. Peter Thiemann University of Freiburg, Germany
Softwaretechnik Lecture 13: Design by Contract Peter Thiemann University of Freiburg, Germany 25.06.2012 Table of Contents Design by Contract Contracts for Procedural Programs Contracts for Object-Oriented
More informationCOMP2111 Glossary. Kai Engelhardt. Contents. 1 Symbols. 1 Symbols 1. 2 Hoare Logic 3. 3 Refinement Calculus 5. rational numbers Q, real numbers R.
COMP2111 Glossary Kai Engelhardt Revision: 1.3, May 18, 2018 Contents 1 Symbols 1 2 Hoare Logic 3 3 Refinement Calculus 5 1 Symbols Booleans B = {false, true}, natural numbers N = {0, 1, 2,...}, integers
More informationMid-Semester Quiz Second Semester, 2012
THE AUSTRALIAN NATIONAL UNIVERSITY Mid-Semester Quiz Second Semester, 2012 COMP2600 (Formal Methods for Software Engineering) Writing Period: 1 hour duration Study Period: 10 minutes duration Permitted
More informationHoare 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 informationGeneralizing Data-flow Analysis
Generalizing Data-flow Analysis Announcements PA1 grades have been posted Today Other types of data-flow analysis Reaching definitions, available expressions, reaching constants Abstracting data-flow analysis
More informationDynamic Semantics. Dynamic Semantics. Operational Semantics Axiomatic Semantics Denotational Semantic. Operational Semantics
Dynamic Semantics Operational Semantics Denotational Semantic Dynamic Semantics Operational Semantics Operational Semantics Describe meaning by executing program on machine Machine can be actual or simulated
More informationLast Time. Inference Rules
Last Time When program S executes it switches to a different state We need to express assertions on the states of the program S before and after its execution We can do it using a Hoare triple written
More informationDenotational Semantics
5 Denotational Semantics In the operational approach, we were interested in how a program is executed. This is contrary to the denotational approach, where we are merely interested in the effect of executing
More informationScalable and Accurate Verification of Data Flow Systems. Cesare Tinelli The University of Iowa
Scalable and Accurate Verification of Data Flow Systems Cesare Tinelli The University of Iowa Overview AFOSR Supported Research Collaborations NYU (project partner) Chalmers University (research collaborator)
More informationSequential programs. Uri Abraham. March 9, 2014
Sequential programs Uri Abraham March 9, 2014 Abstract In this lecture we deal with executions by a single processor, and explain some basic notions which are important for concurrent systems as well.
More informationChapter 4: Classical Propositional Semantics
Chapter 4: Classical Propositional Semantics Language : L {,,, }. Classical Semantics assumptions: TWO VALUES: there are only two logical values: truth (T) and false (F), and EXTENSIONALITY: the logical
More informationLogic: Propositional Logic Truth Tables
Logic: Propositional Logic Truth Tables Raffaella Bernardi bernardi@inf.unibz.it P.zza Domenicani 3, Room 2.28 Faculty of Computer Science, Free University of Bolzano-Bozen http://www.inf.unibz.it/~bernardi/courses/logic06
More informationCritical Reading of Optimization Methods for Logical Inference [1]
Critical Reading of Optimization Methods for Logical Inference [1] Undergraduate Research Internship Department of Management Sciences Fall 2007 Supervisor: Dr. Miguel Anjos UNIVERSITY OF WATERLOO Rajesh
More information3 Propositional Logic
3 Propositional Logic 3.1 Syntax 3.2 Semantics 3.3 Equivalence and Normal Forms 3.4 Proof Procedures 3.5 Properties Propositional Logic (25th October 2007) 1 3.1 Syntax Definition 3.0 An alphabet Σ consists
More informationCHAPTER 4 CLASSICAL PROPOSITIONAL SEMANTICS
CHAPTER 4 CLASSICAL PROPOSITIONAL SEMANTICS 1 Language There are several propositional languages that are routinely called classical propositional logic languages. It is due to the functional dependency
More informationCS156: 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 informationLecture Notes: Program Analysis Correctness
Lecture Notes: Program Analysis Correctness 15-819O: Program Analysis Jonathan Aldrich jonathan.aldrich@cs.cmu.edu Lecture 5 1 Termination As we think about the correctness of program analysis, let us
More informationLecture Notes on Inductive Definitions
Lecture Notes on Inductive Definitions 15-312: Foundations of Programming Languages Frank Pfenning Lecture 2 September 2, 2004 These supplementary notes review the notion of an inductive definition and
More informationIntroduction to Axiomatic Semantics
Introduction to Axiomatic Semantics Meeting 9, CSCI 5535, Spring 2009 Announcements Homework 3 is out, due Mon Feb 16 No domain theory! Homework 1 is graded Feedback attached 14.2 (mean), 13 (median),
More informationSupplementary Notes on Inductive Definitions
Supplementary Notes on Inductive Definitions 15-312: Foundations of Programming Languages Frank Pfenning Lecture 2 August 29, 2002 These supplementary notes review the notion of an inductive definition
More informationHoare 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 informationNotes on Abstract Interpretation
Notes on Abstract Interpretation Alexandru Sălcianu salcianu@mit.edu November 2001 1 Introduction This paper summarizes our view of the abstract interpretation field. It is based on the original abstract
More informationLogical Abduction and its Applications in Program Verification. Isil Dillig MSR Cambridge
Logical Abduction and its Applications in Program Verification? Isil Dillig MSR Cambridge What is Abduction? Abduction: Opposite of deduction 2 / 21 What is Abduction? Abduction: Opposite of deduction
More informationGerwin Klein, June Andronick, Ramana Kumar S2/2016
COMP4161: Advanced Topics in Software Verification {} Gerwin Klein, June Andronick, Ramana Kumar S2/2016 data61.csiro.au Content Intro & motivation, getting started [1] Foundations & Principles Lambda
More informationAbstraction 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