08 April 2009Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and...

15
08 April 2009 Instructor: Tasneem Darwish 1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Formal Methods Relations

Transcript of 08 April 2009Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and...

08 April 2009 Instructor: Tasneem Darwish 1

University of PalestineFaculty of Applied Engineering and Urban Planning

Software Engineering Department

Formal Methods

Relations

08 April 2009 Instructor: Tasneem Darwish 2

Outlines

Relational inverse

Relational composition

Closures

08 April 2009 Instructor: Tasneem Darwish 3

Relational inverseFor a relation R, which is an element of the set , X is the

source set and Y is the target set of R.

The relational inverse (~) operator exchange the source and target.the elements of each ordered pair are exchanged.the result is an element of

The relation R~ maps y to x exactly when R maps x to y

Example 7.9 The inverse of the relation drives, defined in Example 7.2, relates cars to their drivers:

08 April 2009 Instructor: Tasneem Darwish 4

Relational inverseThe relation is homogeneous if the target and source are of the

same type.The relation is heterogeneous if the target and source are not of

the same type.

An important homogeneous relation is the identity relation, defined by

If a homogeneous relation contains the identity relation, then it is reflexive

R is reflexive ifExample 7.11 The relation ≤ upon natural numbers is reflexive; the relation < is not.

08 April 2009 Instructor: Tasneem Darwish 5

Relational inverseA homogenous relation is symmetric if whenever it relates x to y,

it also relates y to x.

A homogeneous relation is antisymmetric, if it is impossible for two different elements to be related in both directions.

A homogeneous relation R is asymmetric if whenever it relates x to y, it doesn’t relate y to x.

Example 7.14 The strict subset relation is asymmetric: it is impossible to find two sets s and t such that

08 April 2009 Instructor: Tasneem Darwish 6

Relational compositionRelational composition is when the target type of one relation

matches the source type of another, and they are combined to form a single relation.

If R is an element of , and S is an element of , then we write to denote the relational composition of R and S which is the element of

08 April 2009 Instructor: Tasneem Darwish 7

Relational compositionExample 7.16 The relation uses of type Cars↔Fuels tells us which fuel is used by each of the cars in Example 7.2:

We may compose the relations drives and uses to find out which fuels a driver may purchase. The type of buys is

08 April 2009 Instructor: Tasneem Darwish 8

Relational compositionA homogeneous relation R is transitive if every pair of connecting

maplets and in R has a corresponding maplet in R.

Example 7.17 The greater-than relation on natural numbers N is transitive: whenever a > b and b > c, we know that a > c

If a homogeneous relation is reflexive, symmetric, and transitive, then it is an equivalence relation:

08 April 2009 Instructor: Tasneem Darwish 9

Closuresthe principle of closure involves adding maplets to a relation until

some useful property is achieved

The simplest form of closure is obtained by adding the identity relation to get reflexive closure

Example 7.21 The reflexive closure <r is the relation .

•The symmetric closure is obtained by adding enough maplets to produce a symmetric relation.

08 April 2009 Instructor: Tasneem Darwish 10

ClosuresFor any positive natural number n, we may write Rn to denote the

composition of n copies of R: that is:

R−n is the inverse of Rn and R0 is the identity relation.

The information obtained from all finite iterations of R can be combined to form the relation R+

08 April 2009 Instructor: Tasneem Darwish 11

ClosuresThe information obtained from all finite iterations of R can be

combined to form the relation R+ R+ is the transitive closure of R; it is the smallest transitive

relation containing R.Example 7.25 We may use a relation direct to record the availability of a direct flight between two airports. For the four airports shown this relation is given by

The composition comprises all of the possibly indirect Flights that involve at most one stop en route

08 April 2009 Instructor: Tasneem Darwish 12

ClosuresExample 7.25 We may use a relation direct to record the availability of a direct flight between two airports. For the four airports shown this relation is given by

The composition comprises all of the possibly indirect Flights that involve at most one stop in route

Two step in route

08 April 2009 Instructor: Tasneem Darwish 13

ClosuresExample 7.25

at most one stop in route

Two step in route

direct4 = direct2 and that direct5 = direct3

08 April 2009 Instructor: Tasneem Darwish 14

ClosuresExample 7.26The transitive closure of direct relates two airports exactly whenthere is a route between them consisting of some number of direct flights

It is sometimes useful to consider the reflexive transitive closure of a homogeneous relation. If R is a relation of type X↔X , then we write R* to denote the smallest relation containing R that is both reflexive and transitive,

08 April 2009 Instructor: Tasneem Darwish 15

ClosuresExample 7.27 In the direct+ relation, there is no way to travel from Perth to Perth.

However, if we are planning the movement of equipment betweenlocations, we might wish to record the fact any equipment already at Perth can be moved to Perth. In this case, we would consider the reflexive transitive closure direct of our flights relation: