THE AUSTRALIAN NATIONAL UNIVERSITY Second Semester 2016 COMP2600/COMP6260 (Formal Methods for Software Engineering) Writing Period: 3 hours duration Study Period: 15 minutes duration Permitted Materials: One A4 page with hand-written notes on both sides Answer ALL questions Total marks: 100 The questions are followed by labelled blank spaces into which your answers are to be written. Additional answer panels are provided (at the end of the paper) should you wish to use more space for an answer than is provided in the associated labelled panels. If you use an additional panel, be sure to indicate clearly the question and part to which it is linked. Student Number: The following spaces are for use by the examiners. Q1 (StrInd) Q2 (FOL) Q3 (NatDed) Q4 (FSA) Q5 (CFL) Q6 (TM) Q7 (Hoare) Q8 (WP) Q9 (SL) Total COMP2600/COMP6260 (Formal Methods for Software Engineering) Page 1 of 5
Additional answers. Clearly indicate the corresponding question and part. Additional answers. Clearly indicate the corresponding question and part. COMP2600/COMP6260 (Formal Methods for Software Engineering) Page 2 of 5
Additional answers. Clearly indicate the corresponding question and part. Additional answers. Clearly indicate the corresponding question and part. COMP2600/COMP6260 (Formal Methods for Software Engineering) Page 3 of 5
Additional answers: deliberately left like this for use in landscape mode. Clearly indicate the corresponding question and part. COMP2600/COMP6260 (Formal Methods for Software Engineering) Page 4 of 5
Additional answers: deliberately left like this for use in landscape mode. Clearly indicate the corresponding question and part. COMP2600/COMP6260 (Formal Methods for Software Engineering) Page 5 of 5
This material to be given to the students as a separate handout, not an appendix to the exam paper! Handout Natural Deduction Rules Propositional Calculus ( I) p q p q ( E) p q p p q q [p] [q] ( I) p p q p q p ( E).. p q r r r [p]. ( I) q p q ( E) p q p q [p] [ p].. ( I) q q p ( E) q q p Predicate Calculus ( I) P(a) (a arbitrary) x. P(x) ( E) x. P(x) P(a) [P(a)] ( I) P(a) x. P(x) ( E) x. P(x). q (a arbitrary) q (a is not free in q)
Handout Truth Table Values p q p q p q p q p p q T T T T T F T T F T F F F F F T T F T T F F F F F T T T
Handout: Regular Expressions Definition of a regular expression Given an alphabet Σ. Regular expressions (RE) over Σ are strings over an alphabet Σ {+,,, ( ), ɛ, } defined inductively as follows 1. Base case: ɛ is a RE is a RE for all a Σ, a is a RE 2. Inductive case: if E and F are RE, then E + F is a RE F is a RE E is a RE (E) is a RE alternation concatenation Kleene star where E is the set of all strings that can be made by concatenating any finite number (including zero) of strings from set described by E. Regular expressions consist of constants that denote sets of strings (base case) and operator symbols that denote operations over these sets (inductive case). Language L(E) defined by RE E is also defined inductively: L(ɛ) = {ɛ} L( ) = L(a) = {a} for each a Σ L(E + F) = L(E) L(F) L(E F) = L(E) L(F) L((E)) = L(E) L(E ) = (L(E)) Concatenation of L 1 and L 2 : L 1 L 2 = {w w = x y, x L 1, y L 2 }
1 Handout : Push-down Automata Definition of a Nondeterministic PDA A nondeterministic PDA has the form (Q, q 0, F, Σ, Γ, Z, δ), where Q is the set of states q 0 Q is the initial state and F Q is the set of the final states Σ is the set of input symbols (the alphabet) Γ is the set of stack symbols (the stack alphabet) Z Γ is the initial stack symbol δ is a transition function δ : Q (Σ {ɛ}) Γ 2 Q Γ Definition of a Deterministic PDA A deterministic PDA has the form (Q, q 0, F, Σ, Γ, Z, δ), where Q is the set of states q 0 Q is the initial state and F Q is the set of the final states Σ is the set of input symbols (the alphabet) Γ is the set of stack symbols (the stack alphabet) Z Γ is the initial stack symbol δ is a (partial) transition function δ : Q (Σ {ɛ}) Γ Q Γ such that for all q Q and s Γ, δ(q, ɛ, s) is defined iff δ(q, a, s) is undefined for all a Σ. Convertion of a CFG to a NPDA Given a CFG G = (Σ, N, S, P). We define a nondeterministic PDA where δ is defined as follows: P = ({q 0, q 1, q f }, q 0, {q f }, Σ, N Σ {Z}, Z, δ) 1. Initialise the process by pushing the start symbol S onto the stack, and entering state q 1 : δ(q 0, ɛ, Z) = {(q 1, SZ)} 2. For each production A α of G define (q 1, α) δ(q 1, ɛ, A) 3. For each terminal symbol t pop the stack, if it matches the input: δ(q 1, t, t) = {(q 1, ɛ)} 4. For termination add the transition to the final state q f : δ(q 1, ɛ, Z) = {(q f, ɛ)}
Handout Hoare Logic Rules Precondition Strengthening: P s P w {P w } S {Q} {P s } S {Q} Postcondition Weakening: Assignment: Sequence: Conditional: While Loop: {P} S {Q s } Q s Q w {P} S {Q w } {Q(e)} x := e {Q(x)} {P} S 1 {Q} {Q} S 2 {R} {P} S 1 ; S 2 {R} {P b} S 1 {Q} {P b} S 2 {Q} {P} if b then S 1 else S 2 {Q} {P b} S {P} {P} while b do S {P b}
Handout Weakest Precondition Rules wp(x := e, Q(x)) Q(e) wp(s 1 ; S 2, Q) wp(s 1, wp(s 2, Q)) wp(if b then S 1 else S 2, Q) (b wp(s 1, Q)) ( b wp(s 2, Q)) (b wp(s 1, Q)) ( b wp(s 2, Q)) P k is the weakest predicate that must be true before while b do S executes, in order for the loop to terminate after exactly k iterations in a state that satisfies Q. P 0 b Q P k+1 b wp(s, P k ) wp(while b do S, Q) k. (k 0 P k )
Handout : Separation Logic Rules Floyd Store Axiom for Separation Logic: replaces Hoare (Store) Axiom {x = v emp} x := e {x = e(v/x) emp} where v is an auxiliary variable which does not occur in e Derived Floyd Store Axiom for Separation Logic: {emp} x := e {x = e emp} where x does not occur in e Fetch Assignment Axiom {(x = v 1 ) (e v 2 )} x := [e] {(x = v 2 ) (e(v 1 /x) v 2 )} where v 1 and v 2 are auxiliary variables which do not occur in e Derived Fetch Assignment Axiom {(e v 2 )} x := [e] {(x = v 2 ) (e v 2 )} where v 2 and x do not occur in e Heap Assignment Axiom {e } [e] := e 1 {e e 1 } where (e ) abbreviates ( z. e z) and z does not occur in e Allocation Assignment Axiom {x = v emp} x := cons(e 1, e 2,, e n ) {x e 1 (v/x), e 2 (v/x),, e n (v/x)} where v is an auxiliary variable different from x and not appearing in e 1, e 2,, e n Derived Allocation Assignment Axiom {emp} x := cons(e 1, e 2,, e n ) {x e 1, e 2,, e n } where x does not appear in e 1, e 2,, e n Dispose Axiom {e } dispose(e) {emp} where (e ) abbreviates ( z. e z) and z does not occur in e The Frame Rule: {P} S {Q} {P R} S {Q R} where no variable modified by S appears free in R Other Rules: the Hoare Logic rules from Handout 3, except the Assignment rule, are also in the calculus for Separation Logic.