300 likes | 495 Views
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.
E N D
CIT Phone Directory Z Specification Document
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
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.
2. The Types [PERSON, PHONE] RESPONSE :: = OK | alreadyKnown |notKnown
3. State definition • Directory • staff: ℙ PERSON • dir: PERSON PHONE • staff = dom dir X Y is the set of relations between X and Y
4. Initial State Init Directory staff =
5. Operations (AddItemOK) AddItemOK Directory name?: PERSON num? : PHONE; r!: RESPONSE {name? ↦ num?} dir staff’ = staff {name?} dir’ = dir {name? ↦ num?} r!=OK
5. Operations (DeleteItemOK) DeleteitemOK Directory name? : PERSON num? : PHONE name? Œ num?dir dir’ = dir \ {name? ↦ num?}
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”.
Relations: domain and range • Teacher-Course== { b ŒITBP120, hhŒITBP220, yaŒITBP120, bb ŒSWEB320} • Domain: domTeacher-Course= { bb, hh, ya} • Range: ran Teacher-Course= { ITBP120, ITBP220, SWEB320}
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 }
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 }
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}
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}
5. Operations (DeleteNameOK) DeleteNameOK Directory name? : PERSON name? staff dir’ = ????? means the tuples whose first element is “name?” will not appear in dir’.
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’.
5. Operations (DeleteNumOK) DeleteNumOK Directory num? : PHONE num? ran dir dir’ = ????? means the tuples whose second element is “num?” will not appear in dir’.
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’.
5. Operations (ListNumOK) ListNumOK Directory name? : PERSON phones! : P PHONE name? staff phones! = {n: PHONE | (name? ↦ n) dir}
5. Operations (ListNamesOK) ListNameOK Directory num? : PHONE names! : P PERSON num? rang dir names! = {n: PERSON | (n ↦ num?) dir}
5. Error Handling AddItemError UAEUSystem name? : PERSON num? : PHONE reply! : RESPONSE (name? ↦ num?) dir reply! = alreadyKnown
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
Modification of functions Consider 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 }
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}
Function override operator Function override adds pairs from f1 to f2 such that it: • acts as a set unionwhen no element of f2 is mapped anywhere by f1 (domf1 domf2 = ), {NouraŒprojectA } { KhadijaŒ projectC } ={NouraŒprojectA } {KhadijaŒ projectC }
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}
The Exam Schedule Z Specification Operations (AddExam) AddExam ExamSchedule course? : COURSE date?: DATE course? courses courses’=courses {course?} exam’ = exam {course? date?} Difference between and
The Exam Schedule Z Specification Operations (ChangeDate) ChangeDate ExamSchedule course? : COURSE date?: DATE course? courses exam’ = exam {course? date?} Difference between and