Docsity

Formal Specification-Software Engineering-Lecture Slides, Slides of Software Engineering

Partial preview of the text

Download Formal Specification-Software Engineering-Lecture Slides and more Slides Software Engineering in PDF only on Docsity!

CS 501: Software Engineering

Fall 2000

Lecture 10

Formal Specification

Administration

Nomadic laptops

  • Study of student use

Next Monday

Discussion about the first presentation

Formal Specification

Ben Potter, Jane Sinclair, David Till,

An Introduction to Formal Specification and Z

(Prentice Hall) 1991

Jonathan Jacky

The Way of Z

(Cambridge University Press) 1997

Mathematical Specification

Example of specification

B

1

, B

2

, ... B

k

is a sequence of m x m matrices

1

2

k

is a sequence of m x m elementary matrices

B

1

1

B

2

2

1

B

k

k ...

2

1

The numerical accuracy must be such that, for all k,

B

k

B

k

- I < 

Formal Specification Using Diagrams

digit

unsigned integer

digit

E

unsigned integer unsigned integer

unsigned number

Two Rules

  • Formal specification does not guarantee correctness
  • Formal specification does not prescribe the implementation

Example: Algorithm

1 + 3 + 5 + ... (2 n - 1) = n

2

Example: Program

int intrt (int a)

/* Calculate integer square root */

int i, term, sum;

term = 1; sum = 1;

for (i = 0; sum <= a; i++)

term = term + 2;

sum = sum + term;

return i;

Finite State Machine

Example:

Therapy control console

[informal description]

State Transition Diagram

Patients Fields Setup Ready

Beam

on

Enter Enter

Start

Stop

Select field

Select patient

(interlock)

(ok)

Z Specification

STATE ::= patients | fields | setup | ready | beam_on

EVENT ::= select_patient | select_field | enter | start | stop

| ok | interlock

FSM == (STATE X EVENT) STATE

no_change, transitions, control : FSM

Continued on next slide

Z Specification (continued)

control = no_change transitions

no_change = { s : STATE ; e : EVENT • ( s , e ) s }

transitions = { ( patients , enter ) fields ,

( fields, select_patient ) patients , ( fields , enter ) setup ,

( setup , select_patient ) patients , ( setup , select_field ) fields ,

( setup , ok ) ready ,

( ready , select_patient ) patients , ( ready , select_field ) fields ,

( ready , start ) beam_on , ( ready , interlock ) setup ,

( beam_on , stop ) ready , ( beam_on , interlock ) setup }

LibSys: An Example of Z

Library system:

  • Stock of books
  • Registered users.
  • Each copy of a book has a unique identifier.
  • Some books on loan; other books on shelves available

for loan.

  • Maximum number of books that any user may have on

loan.

LibSys: Operations

  • Issue a copy of a book to a reader.
  • Reader return a book.
  • Add a copy to the stock.
  • Remove a copy from the stock.
  • Inquire which books are on loan to a reader.
  • Inquire which readers has a particular copy of a book.
  • Register a new reader.
  • Cancel a reader's registration.