Tải bản đầy đủ (.pdf) (40 trang)

Chapter 4 Sets and Functions Discrete Structures for Computer Science (CO1007)

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (707.13 KB, 40 trang )

Relations
Nguyen An Khuong,
Huynh Tuong Nguyen

Chapter 4
Relations

Contents
Properties of Relations

Discrete Structures for Computer Science (CO1007) on Ngày
9 tháng 11 năm 2016

Combining Relations
Representing Relations
Closures of Relations
Types of Relations
Homeworks

Nguyen An Khuong, Huynh Tuong Nguyen
Faculty of Computer Science and Engineering
University of Technology, VNU-HCM
4.1


Contents

Relations
Nguyen An Khuong,
Huynh Tuong Nguyen


1 Properties of Relations
Contents
Properties of Relations

2 Combining Relations

Combining Relations
Representing Relations
Closures of Relations

3 Representing Relations

Types of Relations
Homeworks

4 Closures of Relations
5 Types of Relations
6 Homeworks

4.2


Relations

Introduction

Nguyen An Khuong,
Huynh Tuong Nguyen

Contents

Properties of Relations
Combining Relations
Representing Relations
Closures of Relations
Types of Relations
Homeworks

Function?
4.3


Relations

Relation

Nguyen An Khuong,
Huynh Tuong Nguyen

Definition

Contents

Let A and B be sets. A binary relation (quan hệ hai ngôi) from a
set A to a set B is a set

Properties of Relations
Combining Relations
Representing Relations

R⊆A×B


Closures of Relations
Types of Relations
Homeworks

• Notations:
(a, b) ∈ R ←→ aRb



n-ary relations: R ⊂ A1 × A2 × · · · × An .

4.4


Relations

Example

Nguyen An Khuong,
Huynh Tuong Nguyen

Example

Let A = {a, b, c} be the set of students, B = {l, c, s, g, d} be the
set of the available optional courses. We can have relation R that
consists of pairs (x, y), where x is a student enrolled in course y.

Contents
Properties of Relations

Combining Relations
Representing Relations
Closures of Relations
Types of Relations

R

{(a, l), (a, s), (a, g), (b, c),

=

Homeworks

(b, s), (b, g), (c, l), (c, g)}
R
a
b
c

l
x

c
x

x

s
x
x


g
x
x
x

4.5


Functions as Relations

Relations
Nguyen An Khuong,
Huynh Tuong Nguyen

Contents
Properties of Relations
Combining Relations

• Is a function a relation?
• Yes!
• f : A→B

Representing Relations
Closures of Relations
Types of Relations
Homeworks

R = {(a, b) ∈ A × B | b = f (a)} ⊂ A × B - the graph of f


4.6


Functions as Relations

Relations
Nguyen An Khuong,
Huynh Tuong Nguyen

• Is a relation a function?
Contents

• No

Properties of Relations
Combining Relations
Representing Relations
Closures of Relations
Types of Relations
Homeworks

• Relations are a generalization of functions

4.7


Relations

Relations on a Set


Nguyen An Khuong,
Huynh Tuong Nguyen

Definition

A relation on the set A is a relation from A to A.
Contents

Example

Properties of Relations

Let A be the set {1, 2, 3, 4}. Which ordered pairs are in the
relation R = {(a, b) | a divides b} (a là ước số của b)?

Combining Relations
Representing Relations
Closures of Relations
Types of Relations

Solution:

Homeworks

R = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 4), (3, 3), (4, 4)}

R
1
2
3

4

1
x

2
x
x

3
x

4
x
x

x
x
4.8


Properties of Relations

Relations
Nguyen An Khuong,
Huynh Tuong Nguyen

Contents

Reflexive

(phản xạ)
Symmetric
(đối xứng )
Antisymmetric
(phản đối xứng )
Transitive
(bắc cầu)

xRx, ∀x ∈ A

Properties of Relations
Combining Relations

xRy → yRx, ∀x, y ∈ A

Representing Relations
Closures of Relations
Types of Relations

(xRy ∧ yRx) → x = y, ∀x, y ∈ A

Homeworks

(xRy ∧ yRz) → xRz, ∀x, y, z ∈ A

4.9


Example


Relations
Nguyen An Khuong,
Huynh Tuong Nguyen

Example

Consider the following relations on {1, 2, 3, 4}:
R1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)},
R2 = {(1, 1), (1, 2), (2, 1)},
R3 = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)},
R4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)},
R5 = {(3, 4)}

Contents
Properties of Relations
Combining Relations
Representing Relations
Closures of Relations
Types of Relations
Homeworks

Solution:
• Reflexive: R3
• Symmetric: R2 , R3
• Antisymmetric: R4 , R5
• Transitive: R4 , R5

4.10



Example

Relations
Nguyen An Khuong,
Huynh Tuong Nguyen

Example

Contents
Properties of Relations

What is the properties of the divides (ước số ) relation on the set
of positive integers?
Solution:
• ∀a ∈ Z+ , a | a: reflexive

Combining Relations
Representing Relations
Closures of Relations
Types of Relations
Homeworks

• 1 | 2, but 2 1: not symmetric
• ∀a, b ∈ Z+ , (a | b) ∧ (b | a) → a = b: antisymmetric
• a | b ⇒ ∃k ∈ Z+ , b = ak; b | c ⇒ ∃l ∈ Z+ , c = bl. Hence,

c = a(kl) ⇒ a | c: transitive

4.11



Example

Relations
Nguyen An Khuong,
Huynh Tuong Nguyen

Example

What are the properties of these relations on the set of integers:
R1 = {(a, b) | a ≤ b}
R2 = {(a, b) | a > b}
R3 = {(a, b) | a = b or a = −b}

Contents
Properties of Relations
Combining Relations
Representing Relations
Closures of Relations
Types of Relations
Homeworks

Remark

Counting the number of all relations on a given set having a
certain property is an extremely important and difficult problem.

4.12



Combining Relations

Relations
Nguyen An Khuong,
Huynh Tuong Nguyen

Because relations from A to B are subsets of A × B, two
relations from A to B can be combined in any way two sets can
be combined.

Contents
Properties of Relations

Example

Let A = {1, 2, 3} and B = {1, 2, 3, 4}. List the combinations of
relations R1 = {(1, 1), (2, 2), (3, 3)} and
R2 = {(1, 1), (1, 2), (1, 3), (1, 4)}.

Combining Relations
Representing Relations
Closures of Relations
Types of Relations
Homeworks

Solution: R1 ∪ R2 , R1 ∩ R2 , R1 − R2 and R2 − R1 .
Example

Let A and B be the set of all students and the set of all courses at
school, respectively. Suppose R1 = {(a, b) | a has taken the course

b} and R2 = {(a, b) | a requires course b to graduate}. What are
the relations R1 ∪ R2 , R1 ∩ R2 , R1 ⊕ R2 , R1 − R2 , R2 − R1 ?

4.13


Composition of Relations

Relations
Nguyen An Khuong,
Huynh Tuong Nguyen

Definition
Contents

Let R be relations from A to B and S be from B to C. Then the
composite (hợp thành) of S and R is

Properties of Relations
Combining Relations
Representing Relations

S ◦ R = {(a, c) ∈ A × C | ∃b ∈ B (aRb ∧ bSc)}

Closures of Relations
Types of Relations
Homeworks

Example


R = {(0, 0), (0, 3), (1, 2), (0, 1)}
S = {(0, 0), (1, 0), (2, 1), (3, 1)}
S ◦ R = {(0, 0), (0, 1), (1, 1)}
R ◦ S =?
Remark: R ◦ S = S ◦ R.

4.14


Relations

Power of Relations

Nguyen An Khuong,
Huynh Tuong Nguyen

Definition

Let R be a relation on the set A. The powers (lũy thừa)
Rn , n = 1, 2, 3, . . . are defined recursively by

Contents
Properties of Relations
Combining Relations

R1 = R

and

Rn+1 = Rn ◦ R.


Representing Relations
Closures of Relations
Types of Relations

Example

Homeworks

Let R = {(1, 1), (2, 1), (3, 2), (4, 3)}. Find the powers
Rn , n = 2, 3, 4, . . ..
Solution:
R2 = {(1, 1), (2, 1), (3, 1), (4, 2)}
R3 = {(1, 1), (2, 1), (3, 1), (4, 1)}
R4 = {(1, 1), (2, 1), (3, 1), (4, 1)}
···

4.15


Representing Relations Using Matrices

Relations
Nguyen An Khuong,
Huynh Tuong Nguyen

Definition

Suppose R is a relation from A = {a1 , a2 , . . . , am } to
B = {b1 , b2 , . . . , bn }, R can be represented by the matrix

MR = [mij ], where

Contents
Properties of Relations

mij =

1
0

if(ai , bj ) ∈ R
if(ai , bj ) ∈
/R

Combining Relations
Representing Relations
Closures of Relations
Types of Relations

Example

Homeworks

R is relation from A = {1, 2, 3} to B = {1, 2}. Let
R = {(2, 1), (3, 1), (3, 2)}, the matrix for R is


0 0
MR =  1 0 
1 1

Problem: Determine whether the relation has certain properties
(reflexive, symmetric, antisymmetric,...) basing on its
corresponding matrix?

4.16


Representing Relations Using Digraphs

Relations
Nguyen An Khuong,
Huynh Tuong Nguyen

Definition

Contents

Suppose R is a relation in A = {a1 , a2 , . . . , am }, R can be
represented by the digraph (đồ thị có hướng ) G = (V, E), where

Properties of Relations
Combining Relations
Representing Relations

V =A
(ai , aj ) ∈ E if (ai , aj ) ∈ R

Closures of Relations
Types of Relations
Homeworks


Example

Given a relation on A = {1, 2, 3, 4},
R = {(1, 1), (1, 3), (2, 1), (2, 3), (2, 4), (3, 1), (3, 2), (4, 1)}
Draw corresponding digraph.

4.17


Relations

Resulting digraph

Nguyen An Khuong,
Huynh Tuong Nguyen

Contents
Properties of Relations

1

Combining Relations
Representing Relations
Closures of Relations
Types of Relations
Homeworks

2


4

3

4.18


Closure

Relations
Nguyen An Khuong,
Huynh Tuong Nguyen

Contents

Definition

The closure (bao đóng ) of relation R with respect to property P
is the relation S that
i. contains R

Properties of Relations
Combining Relations
Representing Relations
Closures of Relations
Types of Relations
Homeworks

ii. has property P
iii. is contained in any relation satisfying (i) and (ii).

S is the “smallest” relation satisfying (i) & (ii)

4.19


Relations

Reflexive Closure

Nguyen An Khuong,
Huynh Tuong Nguyen

Example

Contents

Let R = {(a, b), (a, c), (b, d), (d, c)}
The reflexive closure of R
{(a, b), (a, c), (b, d), (d, c), (a, a), (b, b), (c, c), (d, d)}

Properties of Relations
Combining Relations
Representing Relations
Closures of Relations
Types of Relations
Homeworks

R∪∆
where
∆ = {(a, a) | a ∈ A}

diagonal relation (quan hệ đường chéo).

4.20


Reflexive Closure

Relations
Nguyen An Khuong,
Huynh Tuong Nguyen

Contents
Properties of Relations
Combining Relations
Representing Relations
Closures of Relations
Types of Relations
Homeworks

4.21


Relations

Symmetric Closure

Nguyen An Khuong,
Huynh Tuong Nguyen

Example


Contents

Let R = {(a, b), (a, c), (b, d), (c, a), (d, e)}
The symmetric closure of R
{(a, b), (a, c), (b, d), (c, a), (d, e), (b, a), (d, b), (e, d)}

Properties of Relations
Combining Relations
Representing Relations
Closures of Relations
Types of Relations
Homeworks

R ∪ R−
where
R−1 = {(b, a) | (a, b) ∈ R}
inverse relation (quan hệ ngược).

4.22


Symmetric Closure

Relations
Nguyen An Khuong,
Huynh Tuong Nguyen

Contents
Properties of Relations

Combining Relations
Representing Relations
Closures of Relations
Types of Relations
Homeworks

4.23


Relations

Transitive Closure

Nguyen An Khuong,
Huynh Tuong Nguyen

Contents
Properties of Relations

Example

Combining Relations

Let R = {(a, b), (a, c), (b, d), (d, e)}
The transitive closure of R
{(a, b), (a, c), (b, d), (d, e), (a, d), (b, e), (a, e)}

Representing Relations
Closures of Relations
Types of Relations

Homeworks

n
∪∞
n=1 R

4.24


Transitive Closure

Relations
Nguyen An Khuong,
Huynh Tuong Nguyen

Contents
Properties of Relations
Combining Relations
Representing Relations
Closures of Relations
Types of Relations
Homeworks

4.25


×