Docsity

Relations-Formal Specification Methods in Software Development-Lecture Slides, Slides of Software Development Methodologies

Partial preview of the text

Download Relations-Formal Specification Methods in Software Development-Lecture Slides and more Slides Software Development Methodologies in PDF only on Docsity!

Chapter No. 7

Relations

Introduction

  • In a formal specification, it is often

necessary to describe relationships between objects e.g.

  • this record is stored under that key,
  • this input channel is connected to that output channel,
  • this action takes priority over that one
  • These relationships and others like them,

can be described using simple mathematical objects called relations.

Binary Relations

  • Although we may define relations that express links between any finite number of objects, it is enough to employ binary relations
  • The relations that express links between pairs of objects.
  • In our mathematical language, a relation is a set of ordered pairs, a subset of a Cartesian product.
  • If X and Y are sets, then X Y denotes the set of all relations between X and Y

Binary Relations

Definition: If X and Y are two non-empty sets, then

X  Y = {x : X, y : Y • (x, y)}

Example: If X = {a, b}, Y = {0,1} Then

X  Y = {(a, 0), (a, 1), (b, 0), (b, 1)}

Definition: A subset of X  Y is a relation over X 

Y

Example: Compute all relations over X  Y

R 1 = , R 2 = {(a, 0)}, R 3 = {(a, 1)} R 4 = {(b, 0)}, R 4 = {(b, 1)}, R 5 = {(a, 0), (b, 0)},...

There will be 2^4 = 16 number of relations docsity.com

Binary Relations

Example 7.2 : The relation drives is used to record which makes of car are driven by the members of a small group of people.

Notations:

  • If the group of people is defined by

Drivers == {helen, indra, jim, kate} and cars Cars == {alfa, beetle, cortina, deloreang}

  • Then

drives  Drivers  Cars, and the Kate drives cortina = kate  cortina  drives

Binary Relations

Example 7.3 : The relation drives could be defined by

drives : Drivers  Cars

drives = {helen  beetle, indra  alfa, jim  beetle, kate  cortina}

  • That is, Helen and Jim drive Beetles, Indra drives an Alfa, Kate drives a Cortina, and nobody drives a delorean

Domain and Range

  • A relation may contain a great information; often, we require only a small part.
  • To enable us to extract the information that we need, a number of basic functions are included in our mathematical language.
  • The simplest examples are the
    • Domain function
    • Range functions
    • Restriction operator and
    • Subtraction operator

Domain, Range and Restriction Operators

R = {a  1, b  2, c  1, c  3} dom R = {a, b, c}, ran R = {1, 2, 3} Domain Restriction = A  R = {a  1, b  2} Range Restriction = R  B = {b  2, c  3}

a

b

c

d

1

2

3

X Y
R

a

b

A 2

3

B

Subtraction and Relational Image Operators

Domain Subtraction = A  R = {c  1, c  3, d  2} Range Subtraction = R  B = {a  1, c  1} Relational Image = R A  = ran (A  R) = {1, 2}

a

b

c

d

1

2

3

X Y
R

a

b

A 2

3

B

Formal Definitions

Domain Subtraction of A from R:

A  R = {x: X; y: Y | x  y  R  x  A • x  y }

Range Subtraction of B from R:

R  B = {x: X; y: Y | x  y  R  y  B • x  y }

Relational Image of A under R:

R A  = ran (A  R) = {x: X; y: Y | x  y  R  x  A • y }

Identity Relation:

id X = {x: X • x  x }

Homogeneous and Heterogeneous Relation

Homogeneous Relation : If the source and target of a relation have the same type, then we say that the relation is homogeneous Heterogeneous Relation : If the source and target of a relation are different, then we say that the relation is heterogeneous Example 7.10 :

  • The relation < on natural numbers is homogeneous: the source and the target sets are the natural numbers N
  • The relation drives is heterogeneous, because Source is Drivers, target is Cars

Identity Relation

  • An important homogeneous relation is the identity relation, defined by

id X = {x: X • x  x }

  • That is, it associates each element of X with itself, and makes no other associations.
  • The identity relation is useful in reasoning about other relations and in classifying them.
  • If a homogeneous relation contains identity relation, we say that it is reflexive.

Symmetric Relation

  • We say that a relation is symmetric if whenever it relates x to y, it relates y to x.

Symmetric [X] = ={R: XX |  x, y : X • x  y  R  y  x  R }

Example 7.12 : At a business meeting, we might use a relation to record the fact that one person shook hands with another. This relation will be symmetric, this is because

  • If a shook hands with b, then b with a.
  • A symmetric relation is its own inverse:

Anti-symmetric Relation

Definition: A homogeneous relation may be anti-symmetric. In this case, it is impossible for two different elements to be related in both directions.

Anti-symmetric [X] == {R: XX | ( x, y : X •

x  y  R  y  x  R  x = y) }

Example 7.13 : The subset relation  is

anti-symmetric. For any two sets s and t, if s

 t and t  s, then s = t. This fact is often

used to show that two sets are equal.