CIT Phone Directory Z Specification Document

28
1 CIT Phone Directory Z Specification Document

description

CIT Phone Directory Z Specification Document. Sections of a Z document. I ntroduction Types used in the specification State and its invariant properties Initial state Operations and enquiries Error handling Final versions of operations and enquiries. 1. Introduction. - PowerPoint PPT Presentation

Transcript of CIT Phone Directory Z Specification Document

Page 1: CIT  Phone Directory Z Specification Document

1

CIT Phone DirectoryZ Specification Document

Page 2: CIT  Phone Directory Z Specification Document

2

Sections of a Z document

• Introduction• Types used in the specification• State and its invariant properties• Initial state• Operations and enquiries• Error handling• Final versions of operations and enquiries

Page 3: CIT  Phone Directory Z Specification Document

3

1. Introduction

• The CIT wants to write Z specifications for their phone directory. Some people have two phones, and others may share the same phone.

Page 4: CIT  Phone Directory Z Specification Document

4

2. The Types

[PERSON, PHONE] RESPONSE :: = OK | alreadyKnown |notKnown

Page 5: CIT  Phone Directory Z Specification Document

5

3. State definition

Directory staff: PERSONℙ dir: PERSON PHONE

staff = dom dir

X Yis the set of relations between X and Y

Page 6: CIT  Phone Directory Z Specification Document

6

4. Initial State

InitDirectory

staff =

Page 7: CIT  Phone Directory Z Specification Document

7

5. Operations (AddItemOK)

AddItemOK Directory name?: PERSON num? : PHONE; r!: RESPONSE {name? num?} ↦ dir staff’ = staff {name?} dir’ = dir {name? num?} ↦ r!=OK

Page 8: CIT  Phone Directory Z Specification Document

8

5. Operations (DeleteItemOK)

DeleteitemOK Directory name? : PERSON num? : PHONE

name? Œ num? dir dir’ = dir \ {name? num?}↦

Page 9: CIT  Phone Directory Z Specification Document

9

Using maplet notation

• The maplet Œ symbol is used to describe the relation elements:

TeacherCourse == { bb ΠITBP120, hh ΠITBP220,

ya ΠITBP120, bb ΠSWEB320}

bb Œ ITBP120 is read as “bb maps to ITBP120”.

Page 10: CIT  Phone Directory Z Specification Document

10

• Teacher-Course == { b Œ ITBP120, hh Œ ITBP220,

ya ΠITBP120, bb ΠSWEB320}

• Domain:

dom Teacher-Course = { bb, hh, ya }

• Range:

ran Teacher-Course = { ITBP120, ITBP220, SWEB320}

Relations: domain and range

Page 11: CIT  Phone Directory Z Specification Document

11

Operations on relations• Teacher-Course ==

{ bb ΠITBP120, hh ΠITBP220, ya ΠITBP120, bb ΠSWEB320}

• Domain restriction Restricts the relation to only those pairs in which the first element is contained in the set provided:

{ hh } Teacher-Course = { hh ΠITBP220 }

Page 12: CIT  Phone Directory Z Specification Document

12

Operations on relations

• Range restriction Restricts the relation to only those pairs in which the second element is contained in the set provided:

Teacher-Course {ITBP120} = { ya ΠITBP120, bb ΠITBP120 }

Page 13: CIT  Phone Directory Z Specification Document

13

Operations on relations (continued)

• Domain subtraction (also known as domain anti-restriction)

Restricts the relation to only those pairs in which the first element is not contained in the set provided:

{ bb } Teacher-Course = {hh ΠITBP220, ya ΠITBP120}

Page 14: CIT  Phone Directory Z Specification Document

14

Operations on relations (continued)

• Range subtraction (also known as range anti-

restriction)

Restricts the relation to only those pairs in which the second element is not contained in the set provided:

Teacher-Course { ITBP120 } = {hh ΠITBP220, bb ΠSWEB320}

Page 15: CIT  Phone Directory Z Specification Document

15

5. Operations (DeleteNameOK)

DeleteNameOK Directory name? : PERSON

name? staff dir’ = ?????

means the tuples whose first element is “name?” will not appear in dir’.

Page 16: CIT  Phone Directory Z Specification Document

16

5. Operations (DeleteNameOK)

DeleteNameOK Directory name? : PERSON

name? staff dir’ = {name?} dir

means the tuples whose first element is “name?” will not appear in dir’.

Page 17: CIT  Phone Directory Z Specification Document

17

5. Operations (DeleteNumOK)

DeleteNumOK Directory num? : PHONE

num? ran dir dir’ = ?????

means the tuples whose second element is “num?” will not appear in dir’.

Page 18: CIT  Phone Directory Z Specification Document

18

5. Operations (DeleteNumOK)

DeleteNumOK Directory num? : PHONE

num? ran dir dir’ = dir {num?}

means the tuples whose second element is “num?” will not appear in dir’.

Page 19: CIT  Phone Directory Z Specification Document

19

5. Operations (ListNumOK)

ListNumOK Directory name? : PERSON phones! : P PHONE

name? staff

phones! = {n: PHONE | (name? n) ↦ dir}

Page 20: CIT  Phone Directory Z Specification Document

20

5. Operations (ListNamesOK)

ListNameOK Directory num? : PHONE names! : P PERSON

num? rang dir

names! = {n: PERSON | (n num?) ↦ dir}

Page 21: CIT  Phone Directory Z Specification Document

21

5. Error Handling

AddItemError UAEUSystem name? : PERSON num? : PHONE reply! : RESPONSE

(name? num?) ↦ dir reply! = alreadyKnown

Page 22: CIT  Phone Directory Z Specification Document

22

6. Final Versions of Operations and Enquiries

The final versions of operations can be specified, in a linear form, as follows:

AddItem ≡ AddItemOK v AddItemError

Page 23: CIT  Phone Directory Z Specification Document

23

Modification of functionsConsider the following function:

studentproject: PERSON PROJECT studentproject = { Noura Œ projectA, Aisha Œ projectB }If Noura has changed a project, we should change our function. How? We can use Union: studentproject’ = studentproject { Noura Œ newProject }But this produces a relation, not a function: studentproject’ = {Noura Œ projectA, Aisha Œ projectB ,

Noura ΠnewProject }

Page 24: CIT  Phone Directory Z Specification Document

24

Modification of functions (continued)

As a solution, Z provides the function override operator studentproject’ =

studentproject { Noura ΠnewProject }

So the new studentproject set is:

{Noura ΠnewProject , Aisha ΠprojectB }

Page 25: CIT  Phone Directory Z Specification Document

25

Function override operator

Function override adds pairs from f1 to f2 such that it:• acts as a set union when no element of f2 is mapped

anywhere by f1 (dom f1 dom f2 = ),

{Noura ΠprojectA } { Khadija ΠprojectC } =

{Noura ΠprojectA } {Khadija ΠprojectC }

Page 26: CIT  Phone Directory Z Specification Document

26

Function override operator

Function override adds pairs from f1 to f2 such that it:• acts as a domain subtraction and a set union, if any

element of f2 is mapped anywhere by f1,{Noura ΠprojectA } {Noura ΠnewProj}

=

({Noura } studentproject) {Noura ΠnewProj}

Page 27: CIT  Phone Directory Z Specification Document

27

The Exam Schedule Z Specification4. Operations (AddExam)

AddExam ExamSchedule

course? : COURSEdate?: DATE

course? coursescourses’=courses {course?}exam’ = exam {course? date?}

Difference between and

Page 28: CIT  Phone Directory Z Specification Document

28

The Exam Schedule Z Specification4. Operations (ChangeDate)

ChangeDate ExamSchedule

course? : COURSEdate?: DATE

course? courses

exam’ = exam {course? date?}

Difference between and