Lecture 7 - Z-Lanugage With Library System
Lecture 7 - Z-Lanugage With Library System
• pronounced “Zed”
• Based on typed set theory
• The most widely-used formal
specification language
• Specifies a system using
schemas
– Basic building blocks
– Allow modularity
– Easier to understand by using
graphical presentation
Z Schema
Schema name
Name
Declarations Schema signature
contents: N
capacity: N
Predicates Schema
contents capacity predicates
ST S subset
S T S is not contained in T
S T Set of intersection of S and T
S T Set of the union of S and T
PS Powerset of S: the set of all subsets of S
FS Finite powerset of S: the set of all finite subsets of S
S-T Difference
Logical operators
Schema decorations:
Total function → =X Y
Partial function → X Y
Surjection (total) → =X =Y
Bijection → =X Yes =Y
9
Examples
known = { Mark, Cheryl, Eric, Paul }
10
AddBirthday
BirthdayBook
name? : NAME
date? : DATE
name? known
birthday' = birthday {name? date?}
11
FindBirthday
BirthdayBook
name? : NAME
date! : DATE
name? known
date! = birthday(name?)
12
Remind
BirthdayBook
today? : DATE
cards! : P NAME
13
Initialization
InitBirthday
BirthdayBook
known = Ø
14
Deriving Properties
known' = dom birthday'
= dom ( birthday {name? date?} )
= dom birthday dom {name? date?}
= dom birthday { name? }
= known { name? }
15
Case Study 2: Z Specification
A simple case example will help bring these concepts together
We do not for the moment specify what exact type the book
variable would be. The book may be identified by an
alphanumeric string, such as by the book title; alphabetic, such as
by author’s name; numeric, such as by ISBN, etc. It does not
matter for the moment.
But what can this simple system do? How about adding a
book/location pair?
A Library System
AddtoLibrary
Library
abook?: BOOK
aspot? : SHELF
abook? onshelf
location’ = location {abook? aspot?}
Add an operation that given the name of a book, it finds its shelf
FindLocation
Ξ Library
abook?: BOOK
aspot! : SHELF
abook? onshelf
aspot! = location(abook?)
A Library System
ShelfContents
Ξ Library
ashelf?: SHELF
books! : BOOK