Z Notation - PowerPoint PPT Presentation

1 / 39
About This Presentation
Title:

Z Notation

Description:

Representing Bags in Z. Records the name of the element and how many times it occurs in the bag. ... B1,B2 :bag X; x:X. count (B1 U B2 ) x = count B1 x count B2 x ... – PowerPoint PPT presentation

Number of Views:155
Avg rating:3.0/5.0
Slides: 40
Provided by: ise2
Category:
Tags: bag | 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

31
Functions
  • Functions
  • Relations where every element in its domain is
    related to at most one element in the range.
  • Total function
  • A function in which every element in the domain
    is mapped to some element in the range
  • Z Notation
  • isDaughterOf PEOPLE PEOPLE

32
Function Definitions
  • Example Function
  • square Z -gt N
  • ? x Z . Square x x.x
  • Finite Functions
  • SSN PEOPLE N

33
Functions - 3
  • Injective Functions
  • Functions where an element in the range is
    related to at most one element in the domain.
  • Z Notation
  • countryOfCapitol CITIES COUNTRY
  • Surjective Functions
  • A function in which every element in the range is
    related to some element in the domain
  • SSN N PEOPLE

34
Operations on Functions
  • Because functions are relations, all relational
    operations are valid for functions.
  • An Example
  • X,Y
  • first (X x Y) -gt X
  • second (X x Y) -gt Y
  • ? x XyY first(x,y) x /\ second(x,y) y

35
Lambda Notation
  • General Form
  • l declarations predicate term
  • Examples
  • 1. l n N n lt5 n2
  • 2. l n, m N m gt n (m-n)

36
Sequences
  • Sets where order matters
  • Represented as functions in Z
  • Example
  • lt Alice, Bob, Cindygt 1 -gt Alice,2 -gt Bob
  • 3-gt Cindy

37
Operations on Sequences - 1
  • Head, tail front and last
  • Let seq1 X seq x \ltgt
  • Then head, tail can be defined as follows
  • X
  • head seq1 X -gt X
  • tail seq1 X -gt X
  • ? s seq1 X
  • head s s1 /\
  • tail s l n1 .. s 1. S(n1)

38
Concatenating Sequences
  • Concatenation
  • Appending a second list to the back of the first
  • Z notation
  • Example
  • lt1,2,3gtlt4,5gt lt1,2,3,4,5gt
  • X
  • __ seq X x seq X -gt seq X
  • ? s,t seq X st sUn1..t (ns) -gt tn

39
Representing Bags in Z
  • Records the name of the element and how many
    times it occurs in the bag.
  • Hence Bag X X N
  • X
  • count bag X (X N)
  • _ U _ (bag X x bag X) bag X
  • ? x X bag Bag count B (lx X.0) () B
  • ? B1,B2 bag X xX
  • count (B1 U B2 ) x count B1 x count B2 x
Write a Comment
User Comments (0)
About PowerShow.com