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

Similar documents
Mid-Semester Quiz Second Semester, 2012

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

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

Hoare Logic: Part II

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

Hoare Calculus and Predicate Transformers

Dynamic Semantics. Dynamic Semantics. Operational Semantics Axiomatic Semantics Denotational Semantic. Operational Semantics

Weakest Precondition Calculus

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

WITH SOME SAMPLE SOLUTIONS

Program verification. 18 October 2017

(pp ) PDAs and CFGs (Sec. 2.2)

Foundations of Computation

October 6, Equivalence of Pushdown Automata with Context-Free Gramm

Turing Machines Part II

Pushdown Automata (PDA) The structure and the content of the lecture is based on

(pp ) PDAs and CFGs (Sec. 2.2)

The Pumping Lemma. for all n 0, u 1 v n u 2 L (i.e. u 1 u 2 L, u 1 vu 2 L [but we knew that anyway], u 1 vvu 2 L, u 1 vvvu 2 L, etc.

Axiomatic Semantics. Hoare s Correctness Triplets Dijkstra s Predicate Transformers

Hoare Logic I. Introduction to Deductive Program Verification. Simple Imperative Programming Language. Hoare Logic. Meaning of Hoare Triples

Programming Languages and Compilers (CS 421)

Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs

Deductive Verification

Hoare Logic: Reasoning About Imperative Programs

Outline. CS21 Decidability and Tractability. Machine view of FA. Machine view of FA. Machine view of FA. Machine view of FA.

Classical Program Logics: Hoare Logic, Weakest Liberal Preconditions

NPDA, CFG equivalence

Part I: Definitions and Properties

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Please give details of your answer. A direct answer without explanation is not counted.

Pushdown Automata. Notes on Automata and Theory of Computation. Chia-Ping Chen

Axiomatic Semantics. Lecture 9 CS 565 2/12/08

Pushdown Automata: Introduction (2)

Foundations of Informatics: a Bridging Course

CSE 105 THEORY OF COMPUTATION

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 )

Pushdown Automata (2015/11/23)

Automata and Computability. Solutions to Exercises

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Outline. Nondetermistic Finite Automata. Transition diagrams. A finite automaton is a 5-tuple (Q, Σ,δ,q 0,F)

Equivalence of Regular Expressions and FSMs

Homework. Context Free Languages. Announcements. Before We Start. Languages. Plan for today. Final Exam Dates have been announced.

Automata and Computability. Solutions to Exercises

Lecture 13: Turing Machine

Theory of Computation

Program verification using Hoare Logic¹

Pushdown Automata (Pre Lecture)

Einführung in die Computerlinguistik

Miscellaneous. Closure Properties Decision Properties

Floyd-Hoare Style Program Verification

CSE 105 THEORY OF COMPUTATION

HKN CS/ECE 374 Midterm 1 Review. Nathan Bleier and Mahir Morshed

Design of Distributed Systems Melinda Tóth, Zoltán Horváth

CSE 105 THEORY OF COMPUTATION

SCHEME FOR INTERNAL ASSESSMENT TEST 3

Lecture 17: Language Recognition

Hoare Logic: Reasoning About Imperative Programs

CS 455/555: Finite automata

MA/CSSE 474 Theory of Computation

Lecture 17: Floyd-Hoare Logic for Partial Correctness

CPS 220 Theory of Computation Pushdown Automata (PDA)

Computational Models - Lecture 5 1

CS481F01 Solutions 6 PDAS

Push-down Automata = FA + Stack

Proof Rules for Correctness Triples

Turing Machines (TM) Deterministic Turing Machine (DTM) Nondeterministic Turing Machine (NDTM)

Pushdown automata. Twan van Laarhoven. Institute for Computing and Information Sciences Intelligent Systems Radboud University Nijmegen

Computability and Complexity

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

CS375: Logic and Theory of Computing

CFGs and PDAs are Equivalent. We provide algorithms to convert a CFG to a PDA and vice versa.

CSE 355 Test 2, Fall 2016

MTH401A Theory of Computation. Lecture 17

CS21 Decidability and Tractability

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata (cont )

CSE 105 Theory of Computation

Theory of Computation

Introduction to Formal Languages, Automata and Computability p.1/42

Theories of Programming Languages Assignment 5

The Post Correspondence Problem

First Order Logic vs Propositional Logic CS477 Formal Software Dev Methods

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

CpSc 421 Final Exam December 15, 2006

Decidability: Church-Turing Thesis

Deterministic Finite Automata

Lecture Notes: Axiomatic Semantics and Hoare-style Verification

60-354, Theory of Computation Fall Asish Mukhopadhyay School of Computer Science University of Windsor

Section 1 (closed-book) Total points 30

Undecidable Problems and Reducibility

Proof Calculus for Partial Correctness

TAFL 1 (ECS-403) Unit- IV. 4.1 Push Down Automata. 4.2 The Formal Definition of Pushdown Automata. EXAMPLES for PDA. 4.3 The languages of PDA

Tree Adjoining Grammars

DM17. Beregnelighed. Jacob Aae Mikkelsen

Properties of Context-Free Languages

Deterministic Program The While Program

COMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lec. 10 : Context-Free Grammars

CS481F01 Prelim 2 Solutions

Accept or reject. Stack

CSE 105 THEORY OF COMPUTATION

Axiomatic Semantics: Verification Conditions. Review of Soundness of Axiomatic Semantics. Questions? Announcements

Transcription:

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.