0% found this document useful (0 votes)
15 views23 pages

Lecture 7 - Z-Lanugage With Library System

The Z Specification Language, pronounced 'Zed', is a formal specification language based on typed set theory, widely used for system specification through schemas. It includes built-in types, logical and set operators, and allows for modularity and graphical representation of specifications. The document provides case studies for a birthday reminder program and a library management system, illustrating the use of schemas and operations in Z specifications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views23 pages

Lecture 7 - Z-Lanugage With Library System

The Z Specification Language, pronounced 'Zed', is a formal specification language based on typed set theory, widely used for system specification through schemas. It includes built-in types, logical and set operators, and allows for modularity and graphical representation of specifications. The document provides case studies for a birthday reminder program and a library management system, illustrating the use of schemas and operations in Z specifications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Zed Specification Language

• 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

• Schema predicates are always true


• Predicates can refer only to elements in the signature
Type definitions
• Built-in types:
– Z - Integers (…,-3,-2,-1,0,1,2,3,…)
– N == {n : Z | n  0} (natural numbers)
– N1 == {n : Z | n > 0} (positive, non-zero, integers)
– R – Real numbers
– Char – characters
• Types may be defined by enumeration
– Sem_model_types = { relation, entity, attribute }
• Some entities may be ‘given’ and defined later
– [NAME, DATE, PERSON]
• Schemas can be used as types

Intro | Hello World | Schema | Operations


Set operators

ST 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

PQ conjunction: “P and Q”


PQ disjunction: “P or Q”
PQ implication: “If P then Q”
PQ equivalence: : “If P then Q and if Q then P”
t=r term t is equal to term r
tr term t is not equal to term r, that is: (t=r)
Predicates:
x:T.P for all x of type T, P holds
x: T.P there exists an x of type T, for which P holds
Z Specification

Schema decorations:

| name: T name is a constant of type T


item ?: T item is an input or accepts input
item !: T item is an output or holds an output
item’ new state of item after change (post condition)
(item) the schema effects change on item (changes state)
Ξ (item) item is left unchanged by schema (constant state)
Function Summary
Name Symbol dom f One-to- ran f
one?

Total function → =X Y

Partial function → X Y

Injection (total) → =X Yes Y

Surjection (total) → =X =Y

Bijection → =X Yes =Y

Intro | Hello World | Schema | Operations


Case Study 1: Z Specification

A simple case example will help bring these concepts together

We will develop a specification for a very


simple birthday reminder program. Or a
calendar with birthdates.
BirthdayBook
known: P NAME
birthday: NAME DATE

known = dom birthday

9
Examples
known = { Mark, Cheryl, Eric, Paul }

birthday = { Mark April 7,


Cheryl July 9,
Eric July 14,
Paul April 30 }

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

cards! = { n: known | birthday(n) = today? }

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 will develop a specification for a very simple library


management system. In this system, each book will be assigned to
a shelf location, designated by a number. A shelf location of course
may house many books.
A Library System

We introduce the types we need: [BOOK], [SHELF]

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.

The shelf we decide is simply numbered from 1 to whatever.

[SHELF], SHELF :N1


A Library System

So now we can think of an ordered pair of [BOOK,SHELF] which


is generic in with respect to BOOK and specified wrt SHELF. This
renders the whole ordered pair structure generic, in that it would
have to be set to a type (book has to be set to a type) before it can
be instantiated.

Now we can create a simple class, let us call it Library. We do so by


creating a class schema:
Library
onshelf : P BOOK
location: BOOK  SHELF
onshelf =dom location
A Library System

Note that we have not placed a limit on the number of records


that may be stored nor the order in which they are to be stored.

Because location is in a functional relationship with onshelf,


there will always be only one location for a book but many
books may be placed on the same shelf.

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?}

We have read two variables abook and aspot and


A Library System
Let’s add another operation:

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

The new symbol Ξ indicates that the operation FindLocation has


induced no change of state. It is in this sense mathematically
equivalent to:

(onshelf’ = onshelf)  (location’ = location)

Which due to rules of precedence of symbols may be written as:

(onshelf’ = onshelf)  (location’ = location)


A Library System
Another operation may be to find the contents of a shelf. That is,
given the number of the shelf, find out what books are on that shelf.

ShelfContents
Ξ Library
ashelf?: SHELF
books! : BOOK

ashelf?  dom location


books! = {n: onshelf | location(n) = ashelf?}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy