1 relations chapter 9 formal specification using z
Post on 19-Dec-2015
215 views
TRANSCRIPT
![Page 1: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/1.jpg)
1
Relations
Chapter 9
Formal Specification using Z
![Page 2: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/2.jpg)
2
Formal definition of Relation
• The Z examples so far have been limited to one basic type. We need of relating one set to another.
• A relation is a set which is based in the idea of the Cartesian product.
![Page 3: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/3.jpg)
3
Formal definition of Relation
• A Cartesian product is the pairing of values of two or more sets. The Cartesian product is written:
• X Y Z• For example• {red, green} {hardtop,softtop} =• {(red, hardtop), (red, softtop), (green, hardtop), (green,softtop)}
• This set consists of ordered paired called a tuple
![Page 4: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/4.jpg)
4
Formal definition of Relation
• A binary relation R from the set X to the set Y is a subset of the Cartisian Product X Y. If (x,y) R, we write xRy and say x is related to y. In the case X=Y, we call R a binary relation on X.
• The domain of R is the set• { x X | (x,y) R from some y Y}• The range of R is the set• {y Y | (x,y) R for some x X}
![Page 5: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/5.jpg)
5
Relation as a table
• A relation can be thought of as a table that lists the relationship of elements to other elements
Student Course
Bill Computer Science
Mary Maths
Bill Art
Beth History
Beth Computer Science
Dave Math
The table is a set of ordered pairs
![Page 6: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/6.jpg)
6
Relation as a set of ordered Pairs
• If we let
• X = { Bill, Mary, Beth, Dave}
• Y = {ComputerScience, Math, Art, History}
• then the relation from the prevuous table is:
• R = {(Bill,ComputerScience), (Mary, Math), (Bill,Art), (Beth,ComputerScience), (Beth,History), (Dave, Math) }
• We say Mary R Math. The domain is the domain (first column) of R is the set X the range (second column) of R is the set Y. So far the relation has been defined by specifying the ordered pairs involved.
![Page 7: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/7.jpg)
7
Relation defined by rule
• It is also possible to define a relation by giving a rule for membership of the relation.
• Let X = { 2,3,4} and Y = {3,4,5,6,7}• If we define R from X to Y by:• (x,y) R if x divides y (with zero remainder)• We get:• R = { (2,4), (2,6), (3,3), (3,6), (4,4) }
![Page 8: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/8.jpg)
8
Relation written as table
• This can be written as a table .
X Y
2 4
2 6
3 3
3 6
4 4
The domain of R is the set {2,3,4} and the range is {3,4,5}
![Page 9: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/9.jpg)
9
1 2
43
Let R be the relation on X = {1,2,3,4}
defined by :
(x,y) R if x y,
x,y X.
is shown
The digraph for R
R = {(1,1), (1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3),(3,4),(4,4)}
The domain and the range are both equal to x. R is reflexive, transitive and antisymmetric.
![Page 10: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/10.jpg)
10
1 2
43
Let R be the relation on X = {1,2,3,4}
defined by :
(x,y) R if x < y,
x,y X.
is shown
The digraph for R
R = { (1,2),(1,3),(1,4),(2,3),(2,4),(3,4)}
The domain and the range are both equal to x. R is reflexive, transitive and non-symmetric.
![Page 11: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/11.jpg)
11
Types of relation
• A relation R on a set X is reflexive if (x,x) R for every x X.
• A relation R on a set X is symmetric if for all x,y X, if (x,y) R, then (y,x) R.
• A relation R on a set X is antisymmetric if for all x,y X, if (x,y) R, (y,x) and x y , then (y,x) R.
![Page 12: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/12.jpg)
12
Types of relation
• A relation R on a set X is transitive if for all x,y,z X, if (x,y) R, and (y,z) R then (x,z) R.
![Page 13: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/13.jpg)
13
Types of relation
• Let be a relation on the set A, then is reflexive if x x for all x A is symmetric if x y implies y x is transitive if x y and y z imply x z is antisymmetric if x y and y x imply
that x=y
![Page 14: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/14.jpg)
14
Relations
• A special case of Cartesian product is a pair. A binary relation is set of pairs, of related values.
• [COUNTRY] the set of all countries
• [LANGUAGE] set of all languages
![Page 15: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/15.jpg)
15
A relation on COUNTRY and LANGUAGE called SPEAKS could have values: {(France,French),(Canada,French),(Canada,English),(GB,English),(USA,English)}
FranceCanadaGBUSA
COUNTRY
French
English
SPEAKS relation
LANGUAGE
![Page 16: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/16.jpg)
16
RELATIONS
• As can be seen from the SPEAKS relation, there are no restrictions requiring values of the two sets to be paired only one-to-one.
• We are free to choose the direction or order of the relation:
• SPOKEN: (LANGUAGE COUNTRY)
![Page 17: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/17.jpg)
17
Declaring Relations in Z
• R: X Y ( equivalent to (X Y) )
• SPEAKS: COUNTRY LANGUAGE
• ( equivalent to (COUNTRY LANGUAGE) )
• In English we say:
• R relates X to Y.
• SPEAKS relates COUNTRY to LANGUAGE
![Page 18: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/18.jpg)
18
MAPLETS
• A maplet relates x to y and is written:
• x y == (x,y)
• ‘x is related to y’ or ‘x maps to y’
• GB English SPEAKS
• is equivalent to
• (GB, English) SPEAKS
![Page 19: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/19.jpg)
19
Membership
• To discover if a certain pair of values are related it is sufficient to see if the pair or maplet is an element of the relation:
• GB English SPEAKS
• OR
• (GB, English) SPEAKS
![Page 20: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/20.jpg)
20
Infix Notation
• If we declare a relation using low-line characters as place holders to show the fact that is infix
_SPEAKS_ : COUNTRY LANGUAGE
• GB speaks English
• In general
xRy == x y R==(x,y) R
![Page 21: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/21.jpg)
21
The DOMAIN and RANGE of the relation SPEAKSdom SPEAKS is set of countries where at least one language is spoken.ran SPEAKS is set of languages which are spoke in at least one country.
FranceCanadaGBUSA
COUNTRY
(SOURCE)
French
English
SPEAKS relation
dom SPEAKS ran SPEAKS
LANGUAGE(TARGET)
![Page 22: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/22.jpg)
22
Domain and Range
A relation relates values of a set called source or from-set to a set called target or to-set.
Below the source is X and the target Y.R: X Y
R = {(x1,y2), (x2,y2), (x4,y3), (x6, y3) ), (x4,y2)}
![Page 23: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/23.jpg)
23
Domain
In most cases only a subset of of the source is involved in the relation. This subset is called the domain
dom R = {x1,x2,x4,x6}
![Page 24: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/24.jpg)
24
Range
In most cases only a subset of of the target is involved in the relation. This subset is called the range
ran R = {y2,y3}
![Page 25: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/25.jpg)
25
The DOMAIN and RANGE of the relation R dom R = {x1,x2,x4,x6} ran R = {y2,y3}
x1
x2
x4
x6
X
(SOURCE)
Y2
y3
R relation
dom R ran R
Y(TARGET)
x5
x3
y1
y4
![Page 26: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/26.jpg)
26
Relational Image• To discover the set of values from the range
of a relation related to a set of values from the domain of the relation one can use the relational image:
• RS • pronounced the ‘relational image of S in R’.
For the languages spoken in France and Switzerland would be:
• SPEAKS {France, Switzerland} == {French,German, Italian, Romansch}
![Page 27: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/27.jpg)
27
Constant value for a Relation
• Some relations have constant values. If the value of a relation is known, it can be given by an axiomatic definition. For example the infix relation greater-than-or-equal:
i,j:i jn: i=j+ n
![Page 28: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/28.jpg)
28
Domain Restriction
• The domain restriction operator restricts a relation to that part where the domain is contained in a particular set. The relation R domain restricted to S, is written as:
• S R• The point of the operator can be thought
of as pointing left to the domain
![Page 29: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/29.jpg)
29
Range Restriction
• The range restriction operator restricts a relation to that part where the range is contained in a particular set. The relation R range restricted to S, is written as:
• R S• The point of the operator can be
thought of as pointing right to the range
![Page 30: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/30.jpg)
30
Domain Subtraction
• The Domain Subtraction operator restricts a relation to that part where the domain is not contained in a particular set. The relation R domain subtracted to S, is written as:
• S R• The point of the operator can be thought
of as pointing left to the domain
![Page 31: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/31.jpg)
31
Range Subtraction
• The Range Subtraction operator restricts a relation to that part where the Range is not contained in a particular set. The relation R range subtracted to S, is written as:
• R S
![Page 32: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/32.jpg)
32
Example of Domain Restriction
Holsholidays: COUNTRY DATE
• EU: COUNTRY
• The relation mapping only EU countries to their public holidays is:
• EU holidays
• The relation mapping only non-EU countries to their public holidays is:
• EU holidays
![Page 33: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/33.jpg)
33
Composition
• Relations can be joined together in an operation called composition. Given:
• R: X Y and
• Q: Y Z
• We can have forward composition or backward composition
![Page 34: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/34.jpg)
34
Forward Composition
• Given:
• R: X Y and
• Q: Y Z
• forward composition is defined as:
• R;Q: X Z
![Page 35: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/35.jpg)
35
Forward Composition
XZY
R Q
R;Q
![Page 36: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/36.jpg)
36
XZY
R Q
R;Q
For any pair (x,y) related by R forward composed with Q
x R;Q z
there is a y where R relates x to y and Q relates y to z;
y:Y xRy yQz
![Page 37: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/37.jpg)
37
Backward Composition
• Given:
• R: X Y and
• Q: Y Z
• backward composition is defined as:
• QR: R;Q
![Page 38: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/38.jpg)
38
Repeated Composition
• A homogeneous relation is one which relates values from a type to values of the same type. Such a relation can be composed with iteslf
• R: X X
• R ; R: X X
![Page 39: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/39.jpg)
39
Composition Example
• Countries are related by the borders relation if the share a border:
• borders: COUNTRY COUNTRY
• e.g. France borders Switzerland
• Switzerland borders Austria
• Countries are related by borders composed with borders if they each share a border with a third country.
![Page 40: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/40.jpg)
40
Composition Example
• The two facts:– 1. France borders Germany– 2. Germany borders Austria
• can be represented by:
• France borders;borders Austria
• We can write:
• Spain borders3 Denmark
• for
• Spain borders; borders; borders Denmark
![Page 41: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/41.jpg)
41
Transitive Closure
• In general the transitive closure R+ as used in
• x R+ y• means that there is a repeated composition of
R which relates x to y. For example
• France borders+ India.• Means France is on the same land-mass as
India
![Page 42: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/42.jpg)
42
Identity Relation
• The identity relation
• id X
• is the relation which maps all x’s on to themselves:
• id X == {x:X x x }
![Page 43: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/43.jpg)
43
Reflexive Transitive Closure
• The repeated composition
R* = x R+ id X
includes the identity relation. The Reflexive Transitive Closure is similar to the Transitive Closure except that it includes the identity relation. For example
• x R* x is true, even if x R x is false, (id x)
• France borders* France is true
![Page 44: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/44.jpg)
44
Relation Example
• Public holidays around the world can be described as follows:
• [COUNTRY] the set of all countries
• [DATE] the dates of a given year
Holsholidays: COUNTRY DATE
![Page 45: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/45.jpg)
45
Relation Example
• An operation to discover whether a date d? is a public holiday in country c? is:
• REPLY ::= yes | no
EnquireHols
c?: COUNTRY
d?: DATE
rep! : REPLY
c? d?holidays rep! = yes)
c? d?holidays rep! = no)
![Page 46: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/46.jpg)
46
Relation Example
• An operation to decree whether a public holiday in country c? on date d? is:
DecreeHols
c?: COUNTRY
d?: DATE
holidays’ = holidays c? d?
![Page 47: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/47.jpg)
47
Relation Example
• An operation to abolish a public holiday in country c? on date d? is:
AbolishHols
c?: COUNTRY
d?: DATE
holidays’ = holidays \c? d?
![Page 48: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/48.jpg)
48
Relation Example
• An operation to find the dates ds! of all public holidays in country c? is:
DatesHols
c?: COUNTRY
ds?: DATE
ds! = holidays c?
![Page 49: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/49.jpg)
49
Inverse of a relation
• The inverse of a relation R from X to Y
• R: X Y is written
• R~
• and it relate Y to X (mirror image). So if
• x R y
• then
• y R~x
![Page 50: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/50.jpg)
50
Family Example
• [PERSON] the set of all persons
• father,mother: PERSON PERSON
• ‘x father y’ meaning x has father y
• ‘v mother w’ meaning v has mother w
![Page 51: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/51.jpg)
51
Family Example: parent relation
• parent: PERSON PERSON
• can be defined as
• parent = father mother
![Page 52: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/52.jpg)
52
Family Example: sibling
• sibling: PERSON PERSON• can be defined as• sibling = (parent ; parent ~) \ id PERSON• This is defined as the relation parent composed
with its own inverse, in other words the set of persons with the same parent. Note the inverse of parent that relates parent to child. A person is not usually counted as their own sibling, hence the use of the identity relation.
![Page 53: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/53.jpg)
53children ZY
R Q
parent;parent~
sibling: PERSON PERSONcan be defined assibling = (parent ; parent ~) \ id PERSONchildren parents : PERSONchildren = {Pat, Bernard,Marion}parents = {Liam, Mary}
Pat
Bernard
Marion
Liam
Mary
Pat
Bernard
Marion
![Page 54: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/54.jpg)
54children ZY
parentparent~
parent;parent~
(parent ; parent ~) = {(Pat, Pat), (Pat,Bernard), (Pat,Marion), (Bernard, Bernard), (Bernard,Pat), (Bernard,Marion), (Marion,Marion), (Marion,Pat), (Marion,Bernard)}
(parent ; parent ~) \ id PERSON = { (Pat,Bernard), (Pat,Marion),(Bernard,Pat), (Bernard,Marion), (Marion,Pat), (Marion,Bernard)}
Pat
Bernard
Marion
Liam
Mary
Pat
Bernard
Marion
![Page 55: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/55.jpg)
55
Family Example: ANCESTOR
• ancestor: PERSON PERSON
• can be defined as
• ancestor = parent +
• The relation ancestor can be defined as the repeated composition of parent.
![Page 56: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/56.jpg)
56
Chapter 9 Question 1
• Express the fact that the language Latin is not the official language of any country:
![Page 57: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/57.jpg)
57
Chapter 9 Question 1
• Express the fact that the language Latin is not the official language of any country:
• Latin:LANGUAGE
• Latin ran speaks
![Page 58: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/58.jpg)
58
Chapter 9 Question 2
• Express the fact that Switzerland has four languages
![Page 59: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/59.jpg)
59
Chapter 9 Question 2
• Express the fact that Switzerland has four languages
• #speaks {Switzerland} = 4
![Page 60: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/60.jpg)
60
Chapter 9 Question 3
• Give a value to the relation speaksInEU which relates countries which are in the set EU to their languages.
![Page 61: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/61.jpg)
61
Chapter 9 Question 3
• Give a value to the relation speaksInEU which relates countries which are in the set EU to their languages.
• EU: COUNTRY
• speaksInEU : COUNTRY LANGUAGE
• speaksInEU = EU speaks
![Page 62: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/62.jpg)
62
Chapter 9 Question 4
• Give a value to the relation grandParent
![Page 63: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/63.jpg)
63
Chapter 9 Question 4
• Give a value to the relation grandParentgrandParent : PERSON PERSON
grandParent = parent ; parent
![Page 64: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/64.jpg)
64
Chapter 9 Question 5
• A person’s first cousin is defined as a child of the person’s aunt or uncle. Give a value for the relation firstCousin.
![Page 65: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/65.jpg)
65
Chapter 9 Question 5
• A person’s first cousin is defined as a child of the person’s aunt or uncle. Give a value for the relation firstCousin.
firstCousin : PERSON PERSON
firstCousin = (grandParent ; grandParent ~) \ sibling
![Page 66: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/66.jpg)
66
Chapter 9 Question 6
Given
[PERSON] set of uniquely identifiable persons
[MODULE] set module numbers at a university
students,teachers,EU,inter: PERSON
offered: MODULE
studies: PERSON MODULE
teaches: PERSON MODULE
![Page 67: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/67.jpg)
67
Chapter 9 Question 6
[PERSON] set of uniquely identifiable persons
[MODULE] set module numbers at a university
students,teachers,EU,inter: PERSON
offered: MODULE
studies: PERSON MODULE
teaches: PERSON MODULE
Explain the predicates:
EU inter =
EU inter = students
dom studies students
dom teaches teachers
ran studies offered
ran teaches = ran studies
![Page 68: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/68.jpg)
68
Chapter 9 Question 6
Explain the effect of each predicates:
EU inter =
EU inter = students
dom studies students
dom teaches teachers
ran studies offered
ran teaches = ran studies
Students are either from the EU or overseas, but not from both.
Students study and teachers teach.
Only offered modules can be studied.
Those modules that are taught are studied.
![Page 69: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/69.jpg)
69
Chapter 9 Question 7
Give an expression for the set of modules studied by a person p.
![Page 70: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/70.jpg)
70
Chapter 9 Question 7
Give an expression for the set of modules studied by a person p.
studies {p}
![Page 71: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/71.jpg)
71
Chapter 9 Question 8
Give an expression for the number of modules taught by a person q.
![Page 72: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/72.jpg)
72
Chapter 9 Question 8
Give an expression for the number of modules taught by a person q.
#(teaches {q} )
![Page 73: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/73.jpg)
73
Chapter 9 Question 9
• Explain what is meant by the inverse of the relation studies
studies~
![Page 74: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/74.jpg)
74
Chapter 9 Question 9
• Explain what is meant by the inverse of the relation studies
studies~
• The inverse of the relation studies relates modules to persons studying them.
![Page 75: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/75.jpg)
75
Chapter 9 Question 10
• Explain what is meant by the composition of the relations
studies ; teaches~
![Page 76: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/76.jpg)
76
Chapter 9 Question 10
• Explain what is meant by the composition of the relations
studies ; teaches~
• The composition of relates students to the teachers who teach modules the students study.
![Page 77: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/77.jpg)
77
Chapter 9 Question 11
• Give an expression for the set of persons who teach person p.
![Page 78: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/78.jpg)
78
Chapter 9 Question 11
• Give an expression for the set of persons who teach person p.
(studies ; teaches~) {p}
![Page 79: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/79.jpg)
79
Chapter 9 Question 12
• Give an expression for the number of persons who teach both person p and person q.
![Page 80: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/80.jpg)
80
Chapter 9 Question 12
• Give an expression for the number of persons who teach both person p and person q.
#((studies ; teaches~) {p} (studies ; teaches~) {q} )
![Page 81: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/81.jpg)
81
Chapter 9 Question 13
• Give an expression for that part of the relation studies that pertains to international students(inter)
•
![Page 82: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/82.jpg)
82
Chapter 9 Question 13
• Give an expression for that part of the relation studies that pertains to international students(inter)
•
• inter studies
![Page 83: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/83.jpg)
83
Chapter 9 Question 14
• Give an expression for that states that p and q teach some of the same international students.
![Page 84: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/84.jpg)
84
Chapter 9 Question 14
• Give an expression for that states that p and q teach some of the same international students.
((teaches; studies ~) {p} (teaches; studies ~) {q} ) inter
![Page 85: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/85.jpg)
85
Chapter 9 Question 15
• The following declarations are part of the description of an international conference.
[PERSON] set of uniquely identifiable persons
[LANGUAGE] the set of world languages
official: LANGUAGE
![Page 86: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/86.jpg)
86
Chapter 9 Question 15
• The following declarations are part of the description of an international conference.
[PERSON] set of uniquely identifiable persons
[LANGUAGE] the set of world languages
official: LANGUAGE
![Page 87: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/87.jpg)
87
Chapter 9 Question 15
[PERSON] set of uniquely identifiable persons
[LANGUAGE] the set of world languages
official: LANGUAGECONFERENCE PERSONLANGUAGE
_speaks_ : PERSON LANGUAGE
![Page 88: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/88.jpg)
88
Chapter 9 Question 15A
Write expression that states every delegate speaks at least one language
delagates dom speaks
![Page 89: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/89.jpg)
89
Chapter 9 Question 15B
Write expression that states every delegate speaks at least one official language of the conference
delagates ran speaks
![Page 90: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/90.jpg)
90
Chapter 9 Question 15C
Write expression that states every delegate speaks at least one official language of the conference
lang:LANGUAGE
(del:PERSON | del delagates del speaks lang)
![Page 91: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/91.jpg)
91
Chapter 9 Question 15E
• Write an operation schema to register a new delegate and the set of languages he or she speaks.
Registerdel?:PERSON
lang?: LANGUAGE
CONFERENCEdel? delegates
delegates = delegates {del?}
speaks =
speaks {lan:LANGUAGE | lan lang? del? lan}
official = official’
![Page 92: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/92.jpg)
92
Labs
• Using pen and paper do Chapter 2 Exercises 5.
• Using pen and paper do exam example Edward, Fleur, and Gareth.
• Type both of the above into Word using symbols or Z fonts.
![Page 93: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/93.jpg)
93
Labs
• Calculate the following unions.
• S1 = [1,2], S2 = [2, 3, 4, 5], S3 = [1, 2, [2, 3, 4, 5]], union(S1,S2,W).
• S1 = [1,2], S2 = [2, 3, 4, 5], S3 = [1, 2, [2, 3, 4, 5]], union(S1,S3,W).
• S1 = [1,2], S2 = [2, 3, 4, 5], S3 = [1, 2, [2, 3, 4, 5]], union(S3,S2,W).
![Page 94: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/94.jpg)
94
Labs
• Start Prolog
• Copy sets.pro from: X:\distrib\wmt2\maths\prolog
• Consult sets.pro
• Use the sets programs to solve the previous union of S1,S2 and S3.
![Page 95: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/95.jpg)
95
Labs
• Using prolog do exam example Edward, Fleur, and Gareth.
![Page 96: 1 Relations Chapter 9 Formal Specification using Z](https://reader036.vdocument.in/reader036/viewer/2022062421/56649d405503460f94a1abc1/html5/thumbnails/96.jpg)
96
Labs
• 1)Using pen and paper do Chapter 2 Exercises 5.
• 2)Using pen and paper do exam example Edward, Fleur, and Gareth.
• 3)Calculate the following unions.
• S1 = [1,2], S2 = [2, 3, 4, 5], S3 = [1, 2, [2, 3, 4, 5]], union(S1,S2,W).
• S1 = [1,2], S2 = [2, 3, 4, 5], S3 = [1, 2, [2, 3, 4, 5]], union(S1,S3,W).
• S1 = [1,2], S2 = [2, 3, 4, 5], S3 = [1, 2, [2, 3, 4, 5]], union(S3,S2,W).
• 4)Type both 1 and 2 above into Word using symbols or Z fonts.
• 5)Start Prolog
• 6)Copy sets.pro from: X:\distrib\wmt2\maths\prolog
• 7)Consult sets.pro
• 8)Use the sets programs to solve the previous union of S1,S2,S3
• 9)Using prolog do exam example Edward, Fleur, and Gareth.