Z Notation - PowerPoint PPT Presentation

1 / 30
About This Presentation
Title:

Z Notation

Description:

car. cycle. SWE623-Fall 2002. Duminda Wijesekera. 20. Z Notation for Relations - 1 ... Consider a stock database. initialStock: Stock # initialStock maxlines ... – PowerPoint PPT presentation

Number of Views:68
Avg rating:3.0/5.0
Slides: 31
Provided by: ise2
Category:
Tags: notation

less

Transcript and Presenter's Notes

Title: Z Notation


1
Z Notation
  • SWE 623 - Fall 2002
  • Covers Ch 3,4 and 5

2
Chapter 3
3
Conventions
  • Z has types
  • Typed variable
  • Input variables end with ?
  • Output variables end with !
  • Typed constants
  • Has notations for
  • set definitions
  • logical statements and sentences of 1st order
    logic
  • Primed variables Unprimed Variable in post
    state

4
Example (PST Page 43)
  • AddPair
  • Vocab,Vocab set of (Native,Foreign)
  • n?Native f?Foreign
  • Vocab e WellFormedVocabs /\
  • n? e OthoNative /\
  • f? e OrthoForegin /\
  • Vocab Vocab u (n?,f?)

5
Example Cond. (PST Page 40)
  • Native,Foreign
  • OthoNative set of Native
  • OrthoForegin set of Foreign
  • WellFormedVocabs
  • V set of (Native,Foreign)
  • ?n Native f Foreign .(n,f) e V gt
  • n e OrthoNative /\
  • f e OrthoForeign

6
Adding Operations -1
  • Message OK,Error
  • AddValidPair
  • Vocab,Vocab set of (Native,Foreign)
  • n?Native, f?Foreign, rep!Message
  • Vocab e WellFormedVocabs /\
  • n? e OthoNormal /\ f e OrthoForeign /\
  • Vocab Vocab U (n?,f?) /\
  • rep! OK

7
Adding Operations -2
  • Message OK,Error
  • AddValidError
  • Vocab,Vocab set of (Native,Foreign)
  • n?Native, f?Foreign, rep!Message
  • Vocab e WellFormedVocabs /\
  • n? \e OthoNormal \/ f \e OrthoForeign /\
  • Vocab Vocab U (n?,f?) /\
  • rep! Error

8
Adding Operations - 3
  • TotalAddPair AddValidPair U AddPairError
  • Go through the example of ToForeign
  • Suggested Exercises
  • Page 52, 3.3

9
Chapter 4
10
Types and Sets
  • Every declared variable must be typed.
  • OthoNative set of Native
  • x BOOK
  • Set Notations
  • By Explicitly listing elements
  • BOOK,CAR
  • Integers Z, Natural Numbers N
  • Named Sets
  • samllEven 2,4,6,8
  • N1 n e N n gt 0

11
Sets 1
  • Power Set Operator
  • P(S) The set of all subsets of S
  • P(12) f, 1, 2, 1,2
  • Cartesian Product
  • A x B (a,b) a e A /\ b e B
  • Constructing Subtypes Using Sets
  • library P(BOOK x Z)

12
Sets 2
  • Types as Declarations Abbreviations
  • posEven xZ ? yZ x 2y /\ ygt0
  • someEven Z and ? yZ someEven 2y /\ ygt0
  • Can also write someEven posEven
  • Data Types
  • POSITION
  • on, off POSITION and on / off
  • POSITION on off

13
(Free) Type Definitions
  • Disjoint Union Constructor
  • PERSON empltltEMPLOYEEgtgt clientltltCLIENTgt
    gt
  • Product Constructor
  • NAME (FIRST,LAST)
  • Recursive Type Definitions
  • FAMTREE nodeltltNAME x FAMTREE x FAMTREEgtgt
    unk

14
From the Z Library
  • Abbreviations Known to Z
  • Range Restrictions in Ordered Types
  • 25 2,3,4,5
  • 99 9
  • 52 f
  • Counting Function
  • 1,2,3 3
  • 51 0

15
Extending Quantification Notation
  • General Form Declarations Const . Pred
  • ?n N n1 gt n
  • ?x PERSON ? y Parent (x,y)
  • Definite Descriptions m Decs Pred . Expr
  • mx N x5 12
  • For the expression to be DEFINITE, its value
    should be unique.

16
Axiomatic Descriptions
  • Amounts to a formal paragraph
  • maxlines Z
  • maxlines gt 0
  • Abbreviations
  • isParent (PERSON,PERSON)
  • siblings (x,y) xPERSON /\ yPERSON
  • ? z PERSON isParent(x,z) /\
  • isParent(y,z)

17
Generic Definitions(Parameterized Types and
Polymorphism)
  • Example
  • P(X) \ P(X) f for every set X, for example
  • P(N) \ P(N) f and P(Z) \ P(Z) f.
  • Such facts are described as formal paragraphs
  • X
  • f P(X)
  • f xX x /x

18
Chapter 5
  • Z Notation for Functions and Relations

19
Relations
  • A set of ordered pairs
  • Rides (Jane, bus),
  • (Tom,car),
  • (John,cycle),
  • (Jane, car),
  • (Tom,cycle)

Jane Tom John
bus car cycle
20
Z Notation for Relations - 1
  • X lt-gt Y P(X x Y)
  • Can be used for declarations
  • Rides PEOPLE lt-gt VEHICLES
  • Jane -gt Bus, Tom -gt car
  • Can write a formal paragraph as
  • _ Rides _ PEOPLE lt-gt VEHICLES

21
Z Notation for Relations - 2
  • _ lt _ Z lt-gt Z
  • ? x,y Z . ( x lt y ? ? z N . y xz)
  • Domains and Ranges
  • dom R xeX ? yY x -gt y e R
  • ran R yeY ? xX x -gt y e R

22
An Example in Z 1
  • Consider a stock database.
  • initialStock Stock
  • initialStock lt maxlines
  • ? i ITEM n N (i,n)einitalStock /\ nlt100
  • stockItem P ITEM
  • stockItems dom initialStock

23
An Example in Z - Cont
  • Hence if initialStock is
  • widget1 -gt1, widget2 -gt12, widget3 -gt 8
  • Then stockItems is the set
  • widget1, widget2, widget3

24
Operations on Relations
  • Because relations are sets, set operations such
    as union, intersection, difference can be applied
    to them.

25
Example
  • A set of ordered pairs
  • Rides (Jane, bus),
  • (Tom,car),
  • (John,cycle),
  • (Jane, car),
  • (Tom,cycle)
  • Rides U (Ben,tricycle)

Jane Tom John
bus car cycle
tricycle
Ben
26
Other Relational Operators
  • Inverse
  • (x,y)eR-1 ? (y,x)eR
  • (tricycle,ben)eRides-1 ?(ben,tricycle)eRides
  • Domain Restrictions
  • R some domain eltslt R
  • S lt R xXyY xeS /\ x -gty e R
  • femaleRiders jane lt Riders
  • (jane,bus),(jane,car)

27
Other Relational Operators - 2
  • Range Restrictions
  • R R gtsome domain elts
  • R gt T xXyY yeT /\ x -gty e R
  • carRiders Riders gt car
  • (jane,bus),(tom,car)

28
Removing Elements
  • From the Domain
  • S lt R xXyY xeSc /\ x -gt y e R
  • Men lt Riders (jane,bus),(jane,car)
  • From the Range
  • R gt T xXyY yeTc /\ x -gt y e R
  • Riders gt cyclist (jane,bus),(jane,car)
    ,(tom,car)

29
Composing Relations
  • riders PERSON ? vehicles
  • hasWheels Vehicles ? N
  • ridersOnofWheels PERSON ? N
  • R S (x,y) ? z (x,y)eR /\ (y,z)e S

1 2 3 4 5 6
Jane John Tom ben
Car Bus Cycle tricycle
30
Relational Image
  • If R X ? Y and S P(X), then
  • R(S) yY ? xX x e S /\ x -gt y e R
  • R(S) ran( S lt R)
  • Example
  • R(women) car,bus
  • Look at exercises on Page 100
Write a Comment
User Comments (0)
About PowerShow.com