discrete mathematics chapter 7 relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

37
Discrete Mathematic s Chapter 7 Relations 感感 感感感感 感感感感感 感感感感感 感感

Upload: karen-fields

Post on 21-Jan-2016

252 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Discrete Mathematics

Chapter 7

Relations

感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Page 2: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

7.1 Relations and their properties.※The most direct way to express a

relationship between elements of two sets

is to use ordered pairs.

For this reason, sets of ordered pairs are

called binary relations.

Example 1.A : the set of students in your school.B : the set of courses.R = { (a, b) : aA, bB, a is enrolled in course b }

7.1.1

Page 3: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Def 1. Let A and B be sets. A binary relation

from A to B is a subset R of AB.

( Note AB = { (a,b) : aA and bB } )

Def 1’. We use the notation aRb to denote

that (a, b)R, and aRb to denote that

(a,b)R.

Moreover, a is said to be related to b

by R if aRb.

7.1.2

Page 4: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Example 3. Let A={0, 1, 2} and B={a, b},

then {(0,a),(0,b),(1,a),(2,b)} is a relation R

from A to B. This means, for instance, that

0Ra, but that 1Rb

0

1

2

a

b

A B

R

R AB = { (0,a) , (0,b) , (1,a) (1,b) , (2,a) , (2,b)}

R R

7.1.3

Page 5: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Example ( 上例 ) : A : 男生 , B : 女生 , R : 夫妻關系 A : 城市 , B : 州 , 省 R : 屬於 (Example

2)

Note. Relations vs. Functions

A relation can be used to express a 1-to-many

relationship between the elements of the sets

A and B.

( function 不可一對多,只可多對一 )

Def 2. A relation on the set A is a subset of A A ( i.e., a relation from A to A ).

7.1.4

Page 6: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Example 4. Let A be the set {1, 2, 3, 4}. Which ordered pairs are in the relation R = { (a, b)| a divides b }?

Sol :

1

2

3

4

12

3

4

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

7.1.5

Page 7: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Example 5. Consider the following relations on Z.R1 = { (a, b) | a b }

R2 = { (a, b) | a > b }

R3 = { (a, b) | a = b or a = b }

R4 = { (a, b) | a = b }

R5 = { (a, b) | a = b+1 }

R6 = { (a, b) | a + b 3 }

Which of these relationscontain each of the pairs(1,1), (1,2), (2,1), (1,1),and (2,2)?

Sol : (1,1) (1,2) (2,1) (1,1) (2,2)

R1

R2

R3

R4

R5

R6

● ● ●

● ●

● ● ●

● ● ● ●

● ●

7.1.6

Page 8: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Def 3. A relation R on a set A is called reflexive

if (a,a)R for every aA.Example 7. Consider the following relations on

{1, 2, 3, 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) }

which of them are reflexive ?

反身性

Sol : R3

7.1.7

Page 9: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Example 8. Which of the relations from

Example 5 are reflexive ?

Sol :

R1, R3 and R4 7.1.8

R1 = { (a, b) | a b }

R2 = { (a, b) | a > b }

R3 = { (a, b) | a = b or a = b }

R4 = { (a, b) | a = b }

R5 = { (a, b) | a = b+1 }

R6 = { (a, b) | a + b 3 }

Page 10: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Def 4.

(1) A relation R on a set A is called symmetric

if for a, bA, (a, b)R (b, a)R.

(2) A relation R on a set A is called antisymmetric ( 反對稱 ) if for a, bA,

(a, b)R and (b, a)R a = b.

即若 a≠b 且 (a,b)R (b, a)R

7.1.9

Page 11: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Example 10. Which of the relations from Example 7 are symmetric or antisymmetric ? 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) }

Sol : R2, R3 are symmetricR4 are antisymmetric.

7.1.10

Page 12: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Def 5. A relation R on a set A is called transitive( 遞移 ) if for a, b, c A, (a, b)R and (b, c)R (a, c)R.

7.1.11

Page 13: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Example 13. Which of the relations in Example 7 are transitive ? 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) }

Sol : R2 is not transitive since (2,1) R2 and (1,2) R2 but (2,2) R2. R3 is not transitive since (2,1) R3 and (1,4) R3 but (2,4) R3. R4 is transitive.

7.1.12

Page 14: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Example 17. Let A = {1, 2, 3} and B = {1, 2, 3, 4}.

The relation R1 = {(1,1), (2,2), (3,3)}

and R2 = {(1,1), (1,2), (1,3), (1,4)} can be

combined to obtain

R1 ∪ R2

R1 ∩ R2 = {(1,1)}

R1 - R2 = {(2,2), (3,3)}

R2 - R1 = {(1,2), (1,3), (1,4)}

R1 R2 = {(2,2), (3,3), (1,2), (1,3), (1,4)}

Exercise : 1, 7, 437.1.13

symmetric difference, 即 (A B) – (A B)

Page 15: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

補充 :

antisymmetric 跟 symmetric 可並存

(a, b)R, a≠b

sym. (b, a)R

antisym. (b,a)R

故若 R 中沒有 (a, b) with a≠b 即可同時滿足

eg. Let A = {1,2,3}, give a relation R on A s.t. R is both symmetric and antisymmetric, but not reflexive.Sol :

R = { (1,1),(2,2) } 7.1.14

Page 16: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

7.3 Representing Relations by matrices and digraphs

Suppose that R is a relation from A={a1, a2, …, am}

to B = {b1, b2,…, bn }.

The relation R can be represented by the matrix

MR = [mij], where

mij =1, if (ai,bj)R

0, if (ai,bj)R

7.3.1

※ Matrices

Page 17: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Example 1. Suppose that A = {1,2,3} and B = {1,2} Let R = {(a, b) | a > b, aA, bB}. What is MR ?Sol :

0 0

1

1 1

0

11

01

00

RM

7.3.2

1 2

1

2

3

A

B

Page 18: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

※ The relation R is symmetric iff (ai,aj)R (aj,ai)R. This means mij = mji ( 即 MR 是對稱矩陣 ).

1

1

1

RM

tRR MM )(

0

01

1

※ Let A={a1, a2, …,an}. A relation R on A is reflexive iff (ai,ai)R,i.

i.e., a1

…a2 …a1 an

:an

:

a2

對角線上全為 1

7.3.3

Page 19: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

※ The relation R is antisymmetric iff (ai,aj)R and i j (aj,ai)R.

This means that if mij=1 with i≠j, then mji=0.

i.e.,

0

01

00

1

RM

7.3.4

※ transitive 性質不易從矩陣判斷出來

Page 20: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Example 3. Suppose that the relation R on a set is represented by the matrix

110

111

011

RM

Is R reflexive, symmetric, and / or antisymmetric ?

Sol :reflexive, symmetric, not antisymmetric.

7.3.5

Page 21: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

eg. Suppose that S={0,1,2,3} Let R be a relation

containing (a, b) if a b, where a S and b S. Is R reflexive, symmetric, antisymmetric ?

Sol :

1000

1100

1110

1111

RM

00

1 2 3

1

2

3

∴ R is reflexive and antisymmetric, not symmetric.

7.3.6

Page 22: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

※Representing Relations using Digraphs. (directed graphs)

Example 8. Show the directed graph (digraph)

of the relation R={(1,1),(1,3),(2,1),(2,3),(2,4),

(3,1),(3,2),(4,1)} on the set {1,2,3,4}.

Sol :

vertex( 點 ) : 1, 2, 3, 4edge( 邊 ) : 11, 13, 21 23, 24, 31 32, 41

1 2

4 37.3.7

Page 23: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

※ The relation R is reflexive iff for every vertex,

( 每個點上都有 loop)

※ The relation R is symmetric iff

兩點間若有邊,必只有一條邊

7.3.8

※ The relation R is antisymmetric iff

x y

x y

( 兩點間若有邊,必為一對不同方向的邊 )

Page 24: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

※ The relation R is transitive iff for a, b, c A, (a, b)R and (b, c)R (a, c)R.

This means:

a b

d c

a b

d c

( 只要點 x 有路徑走到點 y , x 必定有邊直接連向 y)

7.3.9

Page 25: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Example 10. Determine whether the relations R and S are reflexive, symmetric, antisymmetric, and / or transitive

Sol :

R : a

b c

Exercise : 1,13,26, 27,31

irreflexive( 非反身性 ) 的定義在 p.480即 (a,a)R, aA

7.3.10

a b

c d

Sreflexive,not symmetric,not antisymmetric,not transitive (a→b, b→c, a→c)

not reflexive,symmetricnot antisymmetricnot transitive(b→a, a→c, b→c)

Page 26: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

7.4 Closures of Relations

The relation R={(1,1), (1,2), (2,1), (3,2)} on the set A={1, 2, 3} is not reflexive.

Q: How to construct a smallest reflexive relation Rr such that R Rr ?

7.4.1

※ Closures

Sol: Let Rr = R {(2,2), (3,3)}.

i. e., Rr = R {(a, a)| a A}.

Rr is a reflexive relation containing R that is as small as possible. It is called the reflexive closure of R.

Page 27: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Example 1. What is the reflexive closure of the relation R={(a,b) | a < b} on the set of integers ?

Sol : Rr = R ∪ { (a, a) | aZ }

= { (a, b) | a b, a, bZ }Example :

The relation R={ (1,1),(1,2),(2,2),(2,3),(3,1),(3,2) }on the set A={1,2,3} is not symmetric.

Sol : Let R1={ (a, b) | (a, b)R } Let Rs= R∪R1={ (1,1),(1,2),(2,1),(2,2),(2,3), (3,1),(1,3),(3,2) }Rs is the smallest symmetric relation containing R, called the symmetric closure of R. 7.4.2

Page 28: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Def : 1.(reflexive closure of R on A)

Rr=the smallest set containing R and is reflexive.

Rr=R {∪ (a, a) | aA , (a, a)R}

2.(symmetric closure of R on A)

Rs=the smallest set containing R and is symmetric

Rs=R {∪ (b, a) | (a, b)R & (b, a) R}

3.(transitive closure of R on A)

Rt=the smallest set containing R and is transitive.

Rt=R {∪ (a, c) | (a, b)R & (b, c)R, but (a, c) R}Note. 沒有 antisymmetric closure ,因若不是 antisymmetric , 表示有 a≠b, 且 (a, b) 及 (b, a) 都 R ,此時加任何 pair 都不可能變成 antisymmetric. 7.4.3

Page 29: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Example 2. What is the symmetric closure of the relation R={(a, b) | a > b } on the set of positive integers ?

Sol :

R { (∪ b, a) | a > b }={ (a,b) | a b }

{ (a, b) | a < b }

||

7.4.4

Page 30: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Example. Let R be a relation on a set A, where A={1,2,3,4,5}, R={(1,2),(2,3),(3,4),(4,5)}. What is the transitive closure Rt of R ?Sol :

1

2

3

4

5

∴Rt = (1,2),(2,3),(3,4),(4,5) (1,3),(1,4),(1,5) (2,4),(2,5) (3,5)

Exercise : 1,9( 改為找三種 closure)7.4.5

Page 31: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

7.5 Equivalence Relations ( 等價關係 )Def 1. A relation R on a set A is called an

equivalence relation if it is reflexive,

symmetric, and transitive.

Example 1. Let L(x) denote the length of the string x. Suppose that the relation R={(a,b) | L(a)=L(b), a,b are strings of English letters } Is R an equivalence relation ?Sol :

(a,a)R string a reflexive (a,b)R (b,a)R symmetric (a,b)R,(b,c)R (a,c)R transitive

Yes.

7.5.1

Page 32: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Example 4. (Congruence Modulo m)Let m Z and m > 1. Show that the relation

R={ (a,b) | a≡b (mod m) } is an equivalence relation on the set of integers.

Note that a≡b(mod m) iff m | (ab).∵ a≡a (mod m) (a, a)R reflexive If a≡b(mod m), then ab=km, kZ ba≡(k)m b≡a (mod m) symmetric If a≡b(mod m), b≡c(mod m) then ab=km, bc=lm ac=(k+l)m a≡c(mod m) transitive

∴ R is an equivalence relation.

Sol :

7.5.2

( a is congruent to b modulo m )

Page 33: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Def 2.

Let R be an equivalence relation on a set A.

The equivalence class of the element aA is

[a]R = { s | (a, s)R }

For any b[a]R , b is called a representative of this equivalence class.

Note:If (a, b)R, then [a]R=[b]R.

7.5.3

Page 34: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Example 6.

What are the equivalence class of 0 and 1

for congruence modulo 4 ?

Sol :

Let R={ (a,b) | a≡b (mod 4) }

Then [0]R = { s | (0,s)R }

= { …, 8, 4, 0, 4, 8, … }

[1]R = { t | (1,t)R } = { …,7, 3, 1, 5, 9,…}

7.5.4

Page 35: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Def.

A partition ( 分割 ) of a set S is a collection of disjoint nonempty subsets Ai of S that have S as their union.

In other words, we have

Ai ≠ , i,

Ai∩Aj = , when i≠j

and

∪Ai = S.

7.5.6

Page 36: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Example 7.

Suppose that S={ 1,2,3,4,5,6 }. The collection

of sets A1={1,2,3}, A2={ 4,5 }, and A3={ 6 } form a partition of S.

Thm 2. Let R be an equivalence relation on a set A.

Then the equivalence classes of R form a partition of A.

7.5.7

Page 37: Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供

Example 9.

The congruence modulo 4 form a partition of the integers.

Sol :

[0]4 = { …, 8, 4, 0, 4, 8, … }

[1]4 = { …, 7, 3, 1, 5, 9, … }

[2]4 = { …, 6, 2, 2, 6, 10, … }

[3]4 = { …, 5, 1, 3, 7, 11, … }

Exercise : 3,17,19,237.5.8