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

This lecture was delivered by Sharman Munjha Jadeja at Birla Institute of Technology and Science for Formal Specification Methods in Software Development course. It includes: Relations, Introduction, Homogeneous, Heterogeneous, Binary, Cartesian, Product, Definition

Typology: Slides

2011/2012

Uploaded on 07/09/2012

chand
chand ๐Ÿ‡ฎ๐Ÿ‡ณ

4.4

(7)

31 documents

1 / 35

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Chapter No. 7
Relations
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23

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.