advertisement

COSC 4P42 – Formal Methods in Software Engineering

• Course:

– Lecture: Wed & Fri, 11:00am - 12:30pm, Winter 2015, Room: TH244

– Lab: Fri, 8:00am - 9:30am, Winter 2015, Room: MCD205

• Instructor: Michael Winter

– Office J323

– Office Hours: Tue 1:00pm - 3:00pm, Wed 9:00am-11:00am

– email: [email protected]

• Webpage: www.cosc.brocku.ca/~mwinter/Courses/4P42/

© M. Winter

1

.

1

COSC 4P42 – Formal Methods in Software Engineering

Specification and correctness of software. Topics include algebraic specifications, semantics of programming languages, Hoare/dynamic logic, specification languages, program transformation.

• **Prerequisites: **3.5 COSC credits and MATH 1P67 or permission of the instructor

• course procedures

– cheating on tests/exam

© M. Winter

1

.

2

COSC 4P42 – Formal Methods in Software Engineering

• **Main Text**

– None (course material is on the web page).

• **Supplemental Texts**

– *The Formal Semantics of Programming Languages: An *

*Introduction*, G. Winskel, *The MIT Press *(1993), ISBN 0-262-

23169-7 (hc), 0-262-73103-7 (pb)

– *The Design of Well-Structured and Correct Programs*, S. Alagic &

M.A. Arbib, *Springer-Verlag *(1978), ISBN 0-387-90299-6

– *Fundamentals of Algebraic Specifications 1: Equations and Initial *

*Semantics*, H. Ehrig & B. Mahr, *Springer-Verlag *(1985), ISBN 0-

387-13718-1

© M. Winter

1

.

3

COSC 4P42 – Formal Methods in Software Engineering

**Test Length **

1

2

3

Exam

60 mins

60 mins

60 mins

90 mins

**Date (D205)/Time**

Jan 30 (8:00am-9:00am)

Feb 27 (8:00am-9:00am)

Mar 20 (8:00am-9:00am)

Apr 06 (8:00am-9:30am)

© M. Winter

1

.

4

COSC 4P42 – Formal Methods in Software Engineering

6

7 *

8

9

**Week**

1

2

3

**Date**

Jan 07, 09

Jan 14, 16

Jan 21, 23

4 Jan 28, 30

**Lecture Topic**

Introduction

First-order logic - Syntax and Semantics

First-order logic - Natural Deduction

First-order logic - Soundness of Natural

Deduction

5

10

Feb 25, 27 Programming Language IMP - Hoare Logic

11

12 Apr 01, 06 ** Selected topics, Review

*

February 16-20 is Reading Week, no classes

** April 03 is Good Friday, no classes. Make up on April 06.

© M. Winter

**Lab Topic**

No lab

Introduction to Isabelle

Natural Deduction in Isabelle

Test 1 (Jan 30)

Hoare logic in Isabelle

Hoare logic in Isabelle

Test 2 (Feb 27)

Introduction to ML

Using ML as a specification language in Isabelle

Test 3 (Mar 20)

Review, Questions, Exam preparation

Exam (April 06)

1

.

5

COSC 4P42 – Formal Methods in Software Engineering

• A mark of at least 40% on the final exam is required to achieve a passing grade in this course. No electronic devices and especially no calculators will be allowed in the examination room.

• Consideration regarding illness for test or exam dates will **only** be considered if accompanied with the completed Departmental

Medical Excuse form.

© M. Winter

1

.

6

COSC 4P42 – Formal Methods in Software Engineering

Assume you are a project coordinator in a software company. The latest project your team is working on has the following constraints:

• avoid integer multiplication (there are issues with the hardware);

• the operation square(n)=n 2 will frequently be used in the program.

You present this problem to a member of your team. He comes up with the following piece of code:

© M. Winter

1

.

7

COSC 4P42 – Formal Methods in Software Engineering

r := 0; s := 1; i := 0; while i < n do r := r+s; s := s+2; i := i+1; od

The program above computes n

2 in the variable r.

© M. Winter

1

.

8

COSC 4P42 – Formal Methods in Software Engineering

Input n=

3

6

3

4

1

2

5

6

2

3

0 i

0

1

1

4

9

16

25

36

4

9

0 r

0

1

© M. Winter

7

9

3

5

11

13

5

7

1 s

1

3

1

.

9

COSC 4P42 – Formal Methods in Software Engineering

Testing may unveil errors in the code, but

• You may only test finitely many examples.

• Testing cannot verify that the code is bug-free.

“Correctness cannot be established through testing. Testing can only delete errors, but never exclude errors.”

Are you satisfied with the testing procedure?

Yes?!?, but what if this program

• controls a machine producing toys worth $10,000 an hour?

• controls a rocket sending a new television satellite into orbit?

An error in the code might cause a big financial loss for our company!!!

© M. Winter

1

.

10

COSC 4P42 – Formal Methods in Software Engineering

The programmer says:

“My program obviously computes 𝑛−1

2𝑖 + 1 𝑖=0

Here is the proof that this is equal to n 2 . […]”

© M. Winter

1

.

11

COSC 4P42 – Formal Methods in Software Engineering

Are you satisfied with this proof?

Yes?!?, but what if this program

• controls the reentry of a space shuttle?

• controls the rollercoaster you are sitting in?

• controls the cooling system of the nuclear plant next door?

The previous argument still contains the informal step: 𝑛−1 𝑖=0

This could be wrong!!!!!

© M. Winter

1

.

12

COSC 4P42 – Formal Methods in Software Engineering

An alternative approach is based on so-called formal methods in software engineering. These methods try to either mathematically prove programs to be correct or to construct programs correctly step by step. Both attempts

Require some formal system/calculus , i.e., a system that is based on a fixed set of simple rules. In this course we will focus on program verification.

The idea/procedure of program verification can be summarized by:

• Provide a specification of the behaviour of the program in a formal system/logic.

Common tools are:

– Propositional Logic (hardware verification)

– First-order Logic (properties of imperative programs)

– Higher-order Logic (properties of functional programs)

– Algebraic Specifications (specification of datatypes)

© M. Winter

1

.

13

COSC 4P42 – Formal Methods in Software Engineering

• Provide a formal semantics of the programming language used.

Common approaches are:

– Operational Semantics (abstract machine)

– Denotational Semantics (input/output behaviour as a function)

– Axiomatic Semantics (program logic)

• Use a specialized logic to verify the implementation with respect to the specification.

Common logics are:

– Specific Modal Logics such as Dynamic Logic

– Hoare Logic

– Extended Calculus of Constructions

© M. Winter

1

.

14

COSC 4P42 – Formal Methods in Software Engineering

Important considerations when dealing with a formal system:

• Soundness/Correctness .

This property states that every property that can be obtained using the formal system/calculus is semantically true in some sense.

– Slogan: “What you can prove is also true.”

• Completeness.

This property is the opposite implication of correctness. It states that for every true sentence there is also a proof in the formal system/calculus.

– Slogan: “What is true can also be proven.”

• Expressive power.

– Slogan: “Can I formulate all my properties in the language?”

• Decidability.

If a formal system is decidable, then all proofs can be found automatically by a program.

– Slogan: “Can a computer do my work?”

© M. Winter

1

.

15