CS 501: Software Engineering

1 / 32

# CS 501: Software Engineering - PowerPoint PPT Presentation

CS 501: Software Engineering. Lecture 10 Techniques for Requirements Definition and Specification II . Administration. Formal Specification. Why?  Precise standard to define and validate software. Why not?  May be time consuming  Methods are not suitable for all applications.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about 'CS 501: Software Engineering' - kyle

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
CS 501: Software Engineering

Lecture 10

Techniques for Requirements Definition and Specification II

Formal Specification

Why?

 Precise standard to define and validate software.

Why not?

 May be time consuming

 Methods are not suitable for all applications

Formal Specification using Mathematical Notation

Example:

B1, B2, ... Bk is a sequence of m x m matrices

1, 2, ... k is a sequence of m x m elementarymatrices

B1-1 = 1

B2-1 = 21

Bk-1 = k ... 21

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

BkBk-1 - I<

digit

digit

+

.

E

-

Formal Specification Using Diagrams

Pascal number syntax

unsigned integer

unsigned number

unsigned integer

unsigned integer

Formal Specification of Programming Languages

Pascal number syntax

<unsigned number> ::= <unsigned integer> | <unsigned real>

<unsigned integer> ::= <digit> {<digit>}

<unsigned real> ::= <unsigned integer> . <digit> {<digit>} |

<unsigned integer> . <digit> {<digit>} E <scale factor> |

<unsigned integer> E <scale factor>

<scale factor> ::= <unsigned integer> | <sign> <unsigned integer>

<sign> ::= + | -

Formal Specification using Z ("Zed")

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

Two Rules

 Formal specification does not guarantee correctness

 Formal specification does not prescribe the implementation

Example: Specification using Z

Informal: The function intrt(a) returns the largest integer whose square is less than or equal to a.

Formal (Z):

intrt: NN

a : N •

intrt(a) * intrt(a) < a < (intrt(a) + 1) * (intrt(a) + 1)

Example: Algorithm

Static specification does not describe the design of the system.

A possible algorithm uses the mathematical identity:

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

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;

}

Formal Specification Using Finite State Machine

A broadly used method of formal specification:

 Event driven systems (e.g., games)

 User interfaces

 Protocol specification

etc., etc., ...

Finite State Machine

Example:

Therapy control console

[informal description]

State Transition Diagram

Select field

Start

Enter

Enter

(ok)

Beam

on

Patients

Fields

Setup

Stop

(interlock)

Select patient

State Transition Table

Select

Patient

Select

Field

interlock

ok

Enter

Start

Stop

Patients

Fields

Setup

Patients

Fields

Setup

Fields

Patients

Beam

on

Patients

Fields

Setup

Beam

on

Setup

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,

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

Schemas

Schema:

 Enables complex system to be specifed as subsystems

 The basic unit of formal specification.

 Describes admissible states and operations of a system.

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.

 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.

LibSys

Level of Detail:

Assume given sets:

Global constant:

maxloans

Domain and Range

ran m

X

dom m

Y

m

y

x

m : XY

dom m = { x X :  y  Y  xy}

ran m = { y Y :  x  X  xy}

domain:

range:

<

LibSys: Schema for Abstract States

Library

stock : CopyBook

shelved : FCopy

shelved dom issued = dom stock

shelved dom issued = Ø

r : readers• #(issued {r}) maxloans

<

Schema Inclusion

LibDB

stock : Copy Book

LibLoans

shelved : FCopy

r : Reader• #(issued {r}) maxloans

shelved dom issued = Ø

Schema Inclusion (continued)

Library

LibDB

LibLoans

dom stock = shelved dom issued

Schemas Describing Operations

Naming conventions for objects:

Before: plain variables, e.g., r

After: with appended dash, e.g., r'

Input: with appended ?, e.g., r?

Output: with appended !, e.g., r!

Operation: Issue a Book

 Inputs: copy c?, reader r?

 Copy must be shelved initially: c?  shelved

 Reader must have less than maximum number of books on loan:

#(issued {r?}) < maxloans

 Copy must be recorded as issued to the reader:

issued' = issued {c? r?}

 The stock and the set of registered readers are unchanged:

Operation: Issue a Book

stock, stock' : Copy Book

shelved, shelved': FCopy

[See next slide]

Issue

<

<

Operation: Issue a Book (continued)

Issue

[See previous slide]

shelved dom issued = dom stock

shelved' dom issued' = dom stock'

shelved  dom issued = Ø; shelved'  dom issued' = Ø

r : readers  #(issued {r}) maxloans

r : readers'  #(issued' {r}) maxloans

c? shelved; r?  readers; #(issued  {r?}) < maxloans

issued' = issued  {c? r?}

Schema Decoration

Issue

Library

Library'

c? : Copy; r? : Reader

#(issued {r?}) < maxloans

issued' = issued  {c? r?}

Schema Decoration

Issue

Library

c? : Copy; r? : Reader

#(issued {r?}) < maxloans

issued' = issued  {c? r?}

^

^

=

=

The Schema Calculus

Schema inclusion

Schema decoration

Schema disjunction: