1 lecture 2: relations relations reading: epp chp 10.1, 10.2

78
1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

Upload: bernadette-morrison

Post on 19-Jan-2016

219 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

1

Lecture 2: Relations

RelationsReading: Epp Chp 10.1, 10.2

Page 2: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

2

Overview

0. Motivation

1. Relations1.1 Definition

1.2 Examples

1.3 Notation

1.4 Defining Relations

1.5 More Examples

2. Visualization Tool2.1 Arrow Diagram

2.2 2-D Cartesian Plane

2.3 Graphs

3. Operations of Relations3.1 (Set-related) Union, Intersection, Difference

3.2 Complement of a Relation

3.3 Inverse of a Relation

3.4 Composition of Relations

3.5 Examples

3.6 Proofs

4. Properties of Relations4.1 Reflexive

4.2 Symmetric

4.3 Anti-Symmetric

4.4 Transitive

4.5 Proofs

5. Summary

Page 3: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

3

0. Motivation: Abstraction

Concrete World

Abstract World

a. ___ has been to ___ {John, Mary, Peter} {Tokyo, NY, HK} {(John,Tokyo), (John,NY), (Peter, NY)}

b. ___ is in ___ {Tokyo, NY} {Japan, USA} {(Tokyo,Japan),(NY,USA)}

c. ___ divides ___ {1,2,3,4} {10,11,12} {(1,10),(1,11),(1,12), (2,10), (2,12),(3,12), (4,12)}

d. ___ less than ___ {1,2,3} {1,2,3} {(1,2),(1,3),(2,3)}

___ R ___ A B R A B

Q: What can you do with relations?A: (1) Set Operations; (2) Complement; (3) Inverse; (4) Composition

Q: What happens if A = B?

Relation R from A to B

Page 4: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

4

0. Motivation: Abstraction

Concrete Worlda. ___ same age as ___ {John, Mary, Peter} {(John,John), (Mary,Mary) (Peter,Peter),

(Mary,Peter), (Peter,Mary)}

b. ___ same # of elements as ___

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

c. ___ ___ { {}, {1}, {2}, {1,2} } { ({},{}), ({},{1}), ({},{2}), ({},{1,2}),({1},{1}), ({1},{1,2}), ({2},{2}), ({2},{1,2})

({1,2},{1,2}) }

d. ___ ___ {1,2,3} {(1,1),(1,2),(1,3),(2,2),(2,3),(3,3)}

___ R ___ A R A AObserve anything that is common for all these examples of relations?

Relation R on A

“Everyone is related to himself”

“If x is related to y and y is related to z, then x is related to z.”

Reflexive

Transitive

Page 5: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

5

0. Motivation: Abstraction

Concrete Worlda. ___ same age as ___ {John, Mary, Peter} {(John,John), (Mary,Mary) (Peter,Peter),

(Mary,Peter), (Peter,Mary)}

b. ___ same # of elements as ___

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

c. ___ ___ { {}, {1}, {2}, {1,2} } { ({},{}), ({},{1}), ({},{2}), ({},{1,2}),({1},{1}), ({1},{1,2}), ({2},{2}), ({2},{1,2})

({1,2},{1,2}) }

d. ___ ___ {1,2,3} {(1,1),(1,2),(1,3),(2,2),(2,3),(3,3)}

___ R ___ A R A AObserve anything that differentiates between the examples: (a), (b) and (c), (d) ?

Relation R on A

“If x is related to y, then y is related to x”

“If x is related to y and y is related to x, then x = y.”

Symmetric

Anti-Symmetric

Page 6: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

6

Overview

0. Motivation

1. Relations1.1 Definition

1.2 Examples

1.3 Notation

1.4 Defining Relations

1.5 More Examples

2. Visualization Tool2.1 Arrow Diagram

2.2 2-D Cartesian Plane

2.3 Graphs

3. Operations of Relations3.1 (Set-related) Union, Intersection, Difference

3.2 Complement of a Relation

3.3 Inverse of a Relation

3.4 Composition of Relations

3.5 Examples

3.6 Proofs

4. Properties of Relations4.1 Reflexive

4.2 Symmetric

4.3 Anti-Symmetric

4.4 Transitive

4.5 Proofs

5. Summary

Page 7: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

7

1. Relations

1.1 Definition:

a. A (binary) relation R, from a set A to a set B is a subset of A B.

R A B

b. When A=B, we have a special case of a relation R from A to A. This is also called a relation R on A. We write

R A A

or

R A2

Page 8: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

8

1. Relations

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

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

Is R a relation from A to B?

No.

(ii) R = {(a,1),(b,2)} No.

(iii) R = {} Yes.

(iv) R = {(1,a),(1,b)} Yes.

(v) R = A x B Yes.

(vi) R = {(x,y) | (x,y) A x B, x 1} Yes.

(vii)R = {(x,y) | (x,y) Z x B, x 1} No.

1.2 Examples:

Page 9: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

9

1. Relations

b. Let A = {1,2,3}

(iii) R = {(x,y) | (x,y) A2, x+y>10}

Is R a relation on A?

Yes.

Yes.

No.

Yes.

(iv) R = {(x,y) | (x,y) Z2, 0<x<3 1<y<4}

(v) R = {(x,y) | (x,y) Z2, x+y=4}

(i) R = {}

(ii) R = {(1,2),(2,3),(3,4)} No.

1.2 Examples:

Yes.(vi) R = A2

Page 10: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

10

Expectation required of students (I)

The standard expected of all students is to be able to interpret any new definition given to them, and to be able to check whether a concrete example fits a definition.

This also is applicable to all future topics.

Page 11: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

11

1. Relations

1.3 Notation:– Let R be a relation. If ‘x is-related-to y’, we

write

x R yNote that this is equivalent to saying:

(x,y) Rsince a relation is a set of ordered pairs.

Both notations are expressing the same idea:

x R y iff (x,y) R

Page 12: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

12

1. Relations

1.4 Defining a relation(a) We can define a relation R explicitly by listing every ordered pair that is related.

Example:– A = {1,2,3}, B = {a,b}, R A B

R = {(1,a),(2,b)(3,b),(1,b)}– A = {John, Peter, Mary, Jane}

Loves is a relation on A whereLoves = {(John, Mary), (Mary,Peter),

(Peter, Jane), (Jane, John)}

Page 13: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

13

1. Relations

1.4 Defining a relation(b) We can define a relation R implicitly through a set expression.

Example:– Let A = {1,2,3}, R = {a,b}– Explicit listing: R = {(1,a),(2,b),(3,b),(1,b)}– Implicit listing through Set expression:

R {(x,y) | (x,y) A B, x 1 or y b}

Page 14: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

14

1. Relations

The set expression can be simplified fromR {(x,y) | (x,y) A B, x 1 or y b}

toR A B, x R y iff x 1 or y b

or evenx R y iff x 1 or y b

(when it is clear that R A B)

Page 15: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

15

1. Relations

a. (Relations on things in life)

Let S be the set of people who are or have been living in the world. Let P be a relation on S (P S2) such that

x P y iff x is a parent of y

1.5 Examples

Page 16: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

16

1. Relations

b. (Relations on things in life)

Let S be the set of undergraduates who are studying in School of Computing.Let C be the set of courses offered.Let T be a relation from S to C (T SxC) such that

x T y iff x is taking the course y

T = {(John,cs1101), (John,cs1231), (Peter,cs2103), (Mary,cs3231), …}

1.5 Examples

Page 17: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

17

1. Relations

c. (Relations on numbers)

Defn (remember?): For all integers x and y, (x 0)

x|y iff y = x.k, for some integer k

We read ‘x divides y’ or ‘y is a multiple of x’.

Let D be a relation on Z+ (D (Z+)2) such that

x D y iff x | y

D = {(1,1),(1,2),(1,3),…,(2,2),(2,4),(2,6),…,(3,3),…}

1.5 Examples

Page 18: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

18

1. Relations

e. (Relations on ideas in Geometry)

Let R be the set of real numbers.

Let C be the relation on R such that

x C y iff x2 + y2 = 1

C = {(0,1),(1,0),(0,-1),(-1,0)…}x

y

1

1.5 Examples

Page 19: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

19

1. Relations

f. (Relations on Sets)

Let S = {1,2,3}

Let R be the relation on P(S) such that

A R B iff A B

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

({1},{1,2}) , ({1},{1,3}) , ({1},{1,2,3}) ,…}

1.5 Examples

Page 20: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

20

1. Relations

g. (Relations on Relations!)

Let R1 = {(x,y) Z2 | x+1=y}

Let R2 = {(x,y) Z2 | xy is odd}

Let R be the relation from R1 to R2 such that

(x,y) R (u,v) iff x>u and y<v

R1 = {(1,2),(2,3),(3,4),(4,5),…}

R2 = {(1,1),(1,3),(3,1),(3,3),(1,5),(5,1),(3,5),(5,3),…}

R = { ((2,3),(1,5)) , ((3,4),(1,5)) , ((4,5),(3,7)) , …}

1.5 Examples

Page 21: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

21

Overview

0. Motivation

1. Relations1.1 Definition

1.2 Examples

1.3 Notation

1.4 Defining Relations

1.5 More Examples

2. Visualization Tool2.1 Arrow Diagram

2.2 2-D Cartesian Plane

2.3 Graphs

3. Operations of Relations3.1 (Set-related) Union, Intersection, Difference

3.2 Complement of a Relation

3.3 Inverse of a Relation

3.4 Composition of Relations

3.5 Examples

3.6 Proofs

4. Properties of Relations4.1 Reflexive

4.2 Symmetric

4.3 Anti-Symmetric

4.4 Transitive

4.5 Proofs

5. Summary

Page 22: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

22

2.1 Visualization tool: Arrow Diagram

Let R be a relation on Z+ such that

x R y iff x | y

1

2

3

4

1

2

3

4

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

Page 23: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

23

2.2 Visualization tool: 2D-Cartesian plane

Let R be a relation on Z+ such that

x R y iff x | y

x

y

1 2 3 4 5 6 7

1

2

3

4

5

6

7

Page 24: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

24

2.3 Visualization tool: Graph

Let R be a relation on Z+ such that

x R y iff x | y

1

2 4

356

Page 25: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

25

2.4 Visualization tool (Remarks)

Uncommon Sense

1. When you can draw… draw! What have you got to lose? Nothing! Use every means at your disposal to help you to gain insight to your problem at hand.

2. Choose the appropriate visualization tool. You have three of them at your disposal.– Arrow diagram– 2D-Cartesian plan– Graph

When one of them doesn’t help much, then try another.

3. If the relation is an infinite set, then draw out a subset of the pairs in the relation to get a good feel of the relation.

Page 26: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

26

Overview

0. Motivation

1. Relations1.1 Definition

1.2 Examples

1.3 Notation

1.4 Defining Relations

1.5 More Examples

2. Visualization Tool2.1 Arrow Diagram

2.2 2-D Cartesian Plane

2.3 Graphs

3. Operations of Relations3.1 (Set-related) Union, Intersection, Difference

3.2 Complement of a Relation

3.3 Inverse of a Relation

3.4 Composition of Relations

3.5 Examples

3.6 Proofs

4. Properties of Relations4.1 Reflexive

4.2 Symmetric

4.3 Anti-Symmetric

4.4 Transitive

4.5 Proofs

5. Summary

Page 27: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

27

3. Operations on Relations

3.1: Relations are sets (of ordered pairs). Therefore set operations of

(i) union,

(ii) intersection, and

(iii) difference

are applicable to relations.

If R1 and R2 are relations from A to B, then

R1 R2

R1 R2

R1 – R2

are relations from A to B.

Page 28: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

28

3. Operations on Relations

3.1: Relations are sets (of ordered pairs).

Q: How does R1 R2 look like?

Skill: You must learn to imagine…

Arrow Diagram:

R1

1

2

3

4

1

2

3

4

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

R2

1

2

3

4

1

2

3

4

{(1,2),(2,2),(4,4)}

R1 R2

1

2

3

4

1

2

3

4

{(1,1),(1,2),(1,3),…}

Page 29: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

29

3. Operations on Relations

3.1: Relations are sets (of ordered pairs).

Q: How does R1 R2 look like?

Skill: You must learn to imagine…

2-D Cartesian Plane:

R1 R2 R1 R2

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

{(1,1),(1,2),(1,3),…}

Page 30: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

30

3. Operations on Relations

3.1: Relations are sets (of ordered pairs).

Q: How does R1 R2 look like?

Skill: You must learn to imagine…

Graphs:

R1 R2 R1 R2

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

{(1,1),(1,2),(1,3),…}

1 2

3 4

1 2

3 4

1 2

3 4

Page 31: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

31

3. Operations on Relations

Get the idea?… Various tools are given for you to draw the

relation… With each operation introduced, you also want to

know the effect that it has on the drawing… so that’s why we asked “how will look R1 R2 like?”

Now, you do it! Imagine and think…

Q: How will R1 R2 look like?

Q: How will R1 – R2 look like?

Page 32: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

32

3. Operations on Relations

3.2: Given a relation R from A to B, The complement of the relation R is defined as follows:

R = (A B) – R

(x,y) R iff (x,y) (A B) – R

Note: Do not confuse set complementation with relation complementation.

Page 33: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

33

3.2: Given a relation R from A to B, The complement of the relation R is defined as follows:

R = (A B) – R

(x,y) R iff (x,y) (A B) – R

3. Operations on Relations

1

2

3

a

b

A BR

R{(1,a),(1,b),(3,b)}

Page 34: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

34

3.2: Given a relation R from A to B, The complement of the relation R is defined as follows:

R = (A B) – R

(x,y) R iff (x,y) (A B) – R

3. Operations on Relations

1

2

3

a

b

A B

R{(1,a),(1,b),(3,b)}AB{(1,a),(1,b),(2,a),

(2,b),(3,a),(3,b)}

AB

Page 35: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

35

3. Operations on Relations

3.2: Given a relation R from A to B, The complement of the relation R is defined as follows:

R = (A B) – R

(x,y) R iff (x,y) (A B) – R

1

2

3

a

b

A BR

R{(1,a),(1,b),(3,b)}AB{(1,a),(1,b),(2,a),

(2,b),(3,a),(3,b)}

(AB)R{(2,a), (2,b), (3,b)}

Page 36: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

36

3. Operations on Relations

3.2: Given a relation R from A to B, The complement of the relation R is defined as follows:

R = (A B) – R

(x,y) R iff (x,y) (A B) – R

Now you do it! Imagine and think…

Q: How will complementation affect …

(a) the 2D Cartesian drawing of a relation?

(b) the graph drawing of a relation?

Page 37: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

37

3. Operations on Relations

3.3: Given a relation R from A to B, The inverse of the relation R is defined as follows:

R-1 = {(y,x) | (x,y) R}

(y,x) R-1 iff (x,y) R

NOTE: Do not confuse

inverse of a relation with

complement of a relation

Page 38: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

38

3. Operations on Relations

3.3: Given a relation R from A to B, The inverse of the relation R is defined as follows:

R-1 = {(y,x) | (x,y) R}

(y,x) R-1 iff (x,y) R

1

2

3

a

b

A BR

R{(1,a),(1,b),(3,b)}

Page 39: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

39

3. Operations on Relations

3.3: Given a relation R from A to B, The inverse of the relation R is defined as follows:

R-1 = {(y,x) | (x,y) R}

(y,x) R-1 iff (x,y) R

1

2

3

a

b

A BR-1

R{(1,a),(1,b),(3,b)}R-1 {(a,1),(b,1),(b,3)}

Page 40: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

40

3. Operations on Relations

3.3: Given a relation R from A to B, The inverse of the relation R is defined as follows:

R-1 = {(y,x) | (x,y) R}

(y,x) R-1 iff (x,y) R

Get the idea?… Now are you able to visualize the effect of the inverse on the …

(a) 2D Cartesian drawing of the original relation?

(b) graph drawing of the original relation?

Page 41: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

41

3. Operations on Relations

3.4: Given 2 relations R1 from A to B and R2 from B to C, The composition of the relation R1 and R2 is defined as follows:

R2 o R1 {(x,y) | k, (x,k) R1 (k,y) R2}

(x,y) R2 o R1 iff k, (x,k) R1 (k,y) R2

1

2

3

A

7

5

3

C

a

b

B

d

c

R2R1

1

2

3 7

5

3

A CR2 o R1

Page 42: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

42

3. Operations on Relations

3.4: Given 2 relations R1 from A to B and R2 from B to C, The composition of the relation R1 and R2 is defined as follows:

R2 o R1 {(x,y) | k, (x,k) R1 (k,y) R2}

(x,y) R2 o R1 iff k, (x,k) R1 (k,y) R2

1

2

3

a

b

A B

7

5

3

C

1

2

3 7

5

3

A CR2 o R1R1 R2

d

c

Page 43: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

43

3. Operations on Relations

3.4: Given 2 relations R1 from A to B and R2 from B to C, The composition of the relation R1 and R2 is defined as follows:

R2 o R1 {(x,y) | k, (x,k) R1 (k,y) R2}

(x,y) R2 o R1 iff k, (x,k) R1 (k,y) R2

1

2

3

a

b

A B

7

5

3

C

1

2

3 7

5

3

A CR2 o R1R1 R2

d

c

Page 44: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

44

3. Operations on Relations

3.4: Given 2 relations R1 from A to B and R2 from B to C, The composition of the relation R1 and R2 is defined as follows:

R2 o R1 {(x,y) | k, (x,k) R1 (k,y) R2}

(x,y) R2 o R1 iff k, (x,k) R1 (k,y) R2

How would composition of two relations look like on the …

(a) 2D Cartesian drawing?

(b) graph drawing?

You try to imagine and see…

Page 45: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

45

3. Operations on Relations

3.5 Examples:

Let A {1,3,5}, B {a,b}, C {10,12}

Let R A B, where R {(1,b),(3,a)}

Let S B C, whereS {(a,10),(a,12),(b,12)}

Q: What is R and S?

A: R = {(1,a),(3,b),(5,a),(5,b)} S = {(b,10)}

If you wish, you may draw to have a feel of the problem,… especially when the relation is small and finite and computation is straight-forward.

1

3

5

a

b

R1

3

5

a

b

R

10

12

S

a

b

a

b

S

10

12

(Don’t forget to give the final listing.)

Page 46: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

46

3. Operations on Relations

3.5 Examples:

Let A {1,3,5}, B {a,b}, C {10,12}

Let R A B, where R {(1,b),(3,a)}

Let S B C, whereS {(a,10),(a,12),(b,12)}

Q: What is R and S?A: R = {(1,a),(3,b),(5,a),(5,b)}

S = {(b,10)}

If you are able to observe and compute directly… then go ahead!

Page 47: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

47

3. Operations on Relations

3.5 Examples:

Let A {1,3,5}, B {a,b}, C {10,12}

Let R A B, where R {(1,b),(3,a)}

Let S B C, whereS {(a,10),(a,12),(b,12)}

Q: What is R and S?A: R = {(1,a),(3,b),(5,a),(5,b)}

S = {(b,10)}

Q: What is R-1 and S-1?A: R-1 = {(b,1),(a,3)}

S-1 = {(10,a),(12,a),(12,b)}

Q: What is S o R?A: S o R={(1,12),(3,10),(3,12)}

Q: What is (S o R)-1 ?A: (S o R)-1 = {(10,3),(10,5)}

Work it out bit by bit when things get too complicated.

Page 48: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

48

3. Operations on Relations

3.6.1 Proofs (Theorem 1):

Given any 2 relations, R from A to B and S from B to C, prove that (S o R)-1 = R-1 o S -1.

Draw a diagram to get a feel…

A diagram tells a story…

Page 49: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

49

3. Operations on Relations

3.6.1 Proofs (Theorem 1):

Given any 2 relations, R from A to B and S from B to C, prove that

(x,y) (S o R) (Defn of inverse)

k, (x,k) R (k,y) S (Defn of composition)

k, (k,x) R-1 (y,k) S-1 (Defn of inverse)

k, (y,k) S-1 (k,x) R-1 (-Comm)(y,x) R-1 S-1 (Defn of composition)

Proof (Show LHS RHS and RHS LHS):

(y,x) (S o R)-1

Proven!

11-1)( SR RS

Page 50: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

50

3. Operations on Relations

3.6.2 Proofs (Theorem 2: composition is associative):

Given any 3 relations, R from A to B, S from B to C, and T from C to D prove that (T o S) o R = T o (S o R).

(x,k) R (k,y) (T o S) (Defn of composition)

(x,k) R (k,l) S (l,y) T (Defn of composition)

(x,l) (S o R) (l,y) T (Defn of omposition)(x,y) T o (S o R) (Defn of composition)

Proof (Show LHS RHS and RHS LHS):

(x,y) (T o S) o R

Proven!

Page 51: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

51

Overview

0. Motivation

1. Relations1.1 Definition

1.2 Examples

1.3 Notation

1.4 Defining Relations

1.5 More Examples

2. Visualization Tool2.1 Arrow Diagram

2.2 2-D Cartesian Plane

2.3 Graphs

3. Operations of Relations3.1 (Set-related) Union, Intersection, Difference

3.2 Complement of a Relation

3.3 Inverse of a Relation

3.4 Composition of Relations

3.5 Examples

3.6 Proofs

4. Properties of Relations4.1 Reflexive

4.2 Symmetric

4.3 Anti-Symmetric

4.4 Transitive

4.5 Proofs

5. Summary

Page 52: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

52

4. Properties of Relations ON a set

Common properties for relations on a set:– Reflexive– Symmetric– Anti-Symmetric– Transitive

Page 53: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

53

4. Relations on a Set – Reflexive

4.1 Definition: Let R be a relation on a set A.

R is reflexive iff xA, x R x

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

Is R reflexive?

No.

Example: Let R be a relation on A, A = {1,2,3}

(ii) R = {(1,1)} No.

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

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

Yes.

Yes.

Page 54: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

54

4. Relations on a Set – Reflexive

4.1 Definition: Let R be a relation on a set A.

R is reflexive iff xA, x R x

How does the property look like in a diagram?

x xR

A A

Page 55: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

55

4. Relations on a Set – Symmetric

4.2 Definition: Let R be a relation on a set A.

R is symmetric iff x,yA, x R y y R x

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

Is R symmetric?

No.

Example: Let R be a relation on A, A = {1,2,3}

(ii) R = {(1,1)} Yes.

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

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

Yes.

Yes.

Page 56: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

56

4. Relations on a Set – Symmetric

4.2 Definition: Let R be a relation on a set A.

R is symmetric iff x,yA, x R y y R x

How does the property look like in a diagram?

x yR

A A

y xR

Page 57: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

57

4. Relations on a Set – Anti-Symmetric

4.3 Definition: Let R be a relation on a set A.

R is anti-symmetric iff x,yA, x R y y R x x=y

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

Is R anti-symmetric?

Yes.

Example: Let R be a relation on A, A = {1,2,3}

(ii) R = {(1,2),(2,1)} No.

(iii) R = {(1,1)}

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

Yes.

Yes.

Page 58: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

58

4. Relations on a Set – Anti-Symmetric

4.3 Definition: Let R be a relation on a set A.

R is anti-symmetric iff x,yA, x R y y R x x=y

How does the property look like in a diagram?

x yR

A A

y xR

Page 59: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

59

4. Relations on a Set – Transitive

4.4 Definition: Let R be a relation on a set A.

R is transitive iff x,y,zA, x R y y R z x R z

(i) R = {(1,1)}

Is R transitive?

Yes.

Example: Let R be a relation on A, A = {1,2,3}

(ii) R = {(1,2)} Yes.

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

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

Yes.

No.

(v) R = {(1,2),(2,1)} No.

(vi) R = {(1,2),(2,1),(1,1)} yes.

Page 60: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

60

4. Relations on a Set – Transitive

4.4 Definition: Let R be a relation on a set A.

R is transitive iff x,y,zA, x R y y R z x R z

How does the property look like in a diagram?

x yR

A A

y zR

Page 61: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

61

Note:

‘Anti-symmetric’ is different from ‘not symmetric’. Pay attention to the defn:

R is symmetric iff x,yA, x R y y R x

R is anti-symmetric iff x,yA, x R y y R x x=y

Let R be a relation on {1,2,3}.– Not symmetric, but Anti-symmetric

• R = {(1,2)}

– Symmetric, but Not Anti-symmetric• R = {(1,2),(2,1)}

– Not symmetric, and Not Anti-symmetric• R = {(1,2),(2,1),(1,3)}

– Symmetric, and Anti-symmetric• R = {(1,1),(2,2),(3,3)}

Page 62: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

62

4.5 Proofs

Proving properties: Look at definition!– Reflexive

• xA, (x,x)R

– Symmetric• x,yA, x R y y R x

– Anti-Symmetric• x,yA, x R y y R x x y

– Transitive• x,y,zA, x R y y R z x R z

Page 63: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

63

Expectation required of students (II)

To be able to extract from a given (possibly new) definition, the method of direct proof or the method of disproving by a counter example.

This is applicable to all future topics.

Page 64: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

64

4.5 Proofs

4.5.2 Prove that if R is reflexive, then R o R is reflexive.

Proof: Since R is reflexive, then x R x. Therefore x (R o R) x since there exists a k such that

x R k and k R x: choose k as x.

Page 65: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

65

4.5 Proofs

4.5.3 Prove that if R is symmetric, then R o R is symmetric.

Proof: Since R is symmetric, then x R y y R x. To show: (x,y)(R o R) (y,x)(R o R) Assume (x,y)(R o R)

k, x R k k R y (Defn of composition)

k, k R x y R k (Since R is symmetric)

k, y R k k R x (-Comm)

(y,x) (R o R) (Defn of composition)

Page 66: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

66

4.5 Proofs

Are the following true?– If R is anti-symmetric, then R o R is anti-

symmetric.– If R is transitive, then R o R is transitive.

(Left as an exercise)

Page 67: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

67

4.5 Proofs

4.5.4 Prove or disprove: R R-1 is always anti-symmetric for any relation R.

Is it true… or is it false? Why don’t you explore the statement by trying a few

examples… Maybe you should try to find a counter-example to make it false… if you can’t find it, (in your failure to find a counter-example), you may understand why it is true…

Page 68: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

68

4.5 Proofs

Lesson: Explore using examples

– Try simple ones first– Try a few examples– Try a variety of examples.

Page 69: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

69

4.5 Proofs

4.5.5 Prove or disprove: R R-1 is always symmetric for any relation R.

Try… Let R be this:

R-1 R R-1R

Hmmm… so far it is true… try another one.

Page 70: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

70

4.5 Proofs

4.5.5 Prove or disprove: R R-1 is always symmetric for any relation R.

Let R be this instead…

R R-1

True!…

Insight: Wait a minute… I know why it’s true… if it’s on the diagonal it will still remain on the diagonal upon reflection. But if it’s not on the diagonal, an ‘image’ on the other side will be generated in the inverse, the union will ‘bring both together’…

Correct! Do you realise that you have found your proof?

R R-1

Page 71: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

71

4.5 Proofs

Proof: To prove: R R-1 is symmetric. Need to show: (x,y)(R R-1) (y,x)(R R-1) Assume (x,y)(R R-1)

Therefore (x,y)R or (x,y)R-1 (by defn of union)

If (x,y)R

… then (y,x)R-1 (by defn of inverse)

… then (y,x)R or (y,x)R-1

… then (y,x)(R R-1) (by defn of union)

If (x,y)R-1

… then (y,x)R (by defn of inverse)

… then (y,x)R or (y,x)R-1

… then (y,x)(R R-1) (by defn of union)

Therefore in either case, (y,x)(R R-1).

4.5.5 Prove or disprove: R R-1 is always symmetric for any relation R.

Page 72: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

72

4.5 Proofs

Are the following true?– If R is anti-symmetric, then R o R is anti-

symmetric.– If R is transitive, then R o R is transitive.

(Left as an exercise)

Page 73: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

73

5. Summary

Axiomatic Definitions:– Relation from A to B: R A B– Relation on A: R A A or R A2

– Complemention: (x,y) R iff (x,y) (A B) – R– Inverse: (y,x) R-1 iff (x,y) R

– Composition: (x,y) R2 o R1 iff k, (x,k) R1 (k,y) R2

– Reflexive: xA, (x,x)R

– Symmetric: x,yA, x R y y R x

– Anti-Symmetric: x,yA, x R y y R x x = y

– Transitive: x,y,zA, x R y y R z x R z

Page 74: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

74

5. Summary

Skills: Given a new definition

– To be able to check whether an example fits the definition.– To be able to translate the definition to diagrams and thus

understanding the intuition behind the definition.– To be able to extract the method of direct proof and method

of counter-example from the definition. Given a problem, to be able to gain insight to the problem

by:– Using diagrams (if possible) and if there’s more than one

tool to visualize, then to select the appropriate one which helps in the current situation);

and/or– Trying some concrete examples:

• Trying simple ones first• Trying a few examples• Trying a variety of examples.

Page 75: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

75

Concept of relations are used in Relational Databases

2 Important operations are used in RDBMS: Joins (a more generalised way to define cartesian product), and Projections.

Page 76: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

76

Name M# M# CseCde

Name M# CseCde

Join

Page 77: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

77

Name M#

Name

Projection

Page 78: 1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2

78

End of lecture.