Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2."— Presentation transcript:

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

2 2 Overview 0.Motivation 1.Relations 1.1 Definition 1.2 Examples 1.3 Notation 1.4 Defining Relations 1.5 More Examples 2.Visualization Tool 2.1 Arrow Diagram 2.2 2-D Cartesian Plane 2.3 Graphs 3.Operations of Relations 3.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 Relations 4.1 Reflexive 4.2 Symmetric 4.3 Anti-Symmetric 4.4 Transitive 4.5 Proofs 5.Summary

3 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),(1,3),(2,3)} ___ R ___ AB R  A  BR  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

4 4 0. Motivation: Abstraction Concrete World a. ___ 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  AR  A  A Observe 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

5 5 0. Motivation: Abstraction Concrete World a. ___ 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  AR  A  A Observe 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

6 6 Overview 0.Motivation 1.Relations 1.1 Definition 1.2 Examples 1.3 Notation 1.4 Defining Relations 1.5 More Examples 2.Visualization Tool 2.1 Arrow Diagram 2.2 2-D Cartesian Plane 2.3 Graphs 3.Operations of Relations 3.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 Relations 4.1 Reflexive 4.2 Symmetric 4.3 Anti-Symmetric 4.4 Transitive 4.5 Proofs 5.Summary

7 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  A 2

8 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 BYes. (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:

9 9 1. Relations b. Let A = {1,2,3} (iii)R = {(x,y) | (x,y)  A 2, x+y>10} Is R a relation on A? Yes. No. Yes. (iv)R = {(x,y) | (x,y)  Z 2, 0<x<3  1<y<4} (v)R = {(x,y) | (x,y)  Z 2, x+y=4} (i)R = {} (ii)R = {(1,2),(2,3),(3,4)}No. 1.2 Examples: Yes. (vi)R = A 2

10 10 Expectation required of students (I) n 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. n This also is applicable to all future topics.

11 11 1. Relations 1.3 Notation: –Let R be a relation. If ‘ x is-related-to y ’, we write x R y Note that this is equivalent to saying: (x,y)  R(x,y)  R since a relation is a set of ordered pairs. Both notations are expressing the same idea: x R y iff (x,y)  R

12 12 1. Relations 1.4 Defining a relation (a) We can define a relation R explicitly by listing every ordered pair that is related. n 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 where Loves = {(John, Mary), (Mary,Peter), (Peter, Jane), (Jane, John)}

13 13 1. Relations 1.4 Defining a relation (b) We can define a relation R implicitly through a set expression. n 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}

14 14 1. Relations n The set expression can be simplified from R  {( x, y ) | ( x, y )  A  B, x  1 or y  b} to R  A  B, x R y iff x  1 or y  b or even x R y iff x  1 or y  b (when it is clear that R  A  B )

15 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  S 2 ) such that x P y iff x is a parent of y 1.5 Examples

16 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

17 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

18 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 x 2 + y 2 = 1 C = {(0,1),(1,0),(0,-1),(-1,0)…} x y 1 1.5 Examples

19 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

20 20 1. Relations g. (Relations on Relations!) Let R 1 = { (x,y)  Z 2 | x+1=y } Let R 2 = { (x,y)  Z 2 | xy is odd} Let R be the relation from R 1 to R 2 such that (x,y) R (u,v) iff x>u and y<v R 1 = {(1,2),(2,3),(3,4),(4,5),…} R 2 = {(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

21 21 Overview 0.Motivation 1.Relations 1.1 Definition 1.2 Examples 1.3 Notation 1.4 Defining Relations 1.5 More Examples 2.Visualization Tool 2.1 Arrow Diagram 2.2 2-D Cartesian Plane 2.3 Graphs 3.Operations of Relations 3.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 Relations 4.1 Reflexive 4.2 Symmetric 4.3 Anti-Symmetric 4.4 Transitive 4.5 Proofs 5.Summary

22 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),…

23 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 1234567 1 2 3 4 5 6 7

24 24 2.3 Visualization tool: Graph Let R be a relation on Z + such that x R y iff x | y 1 2 4 3 5 6

25 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.

26 26 Overview 0.Motivation 1.Relations 1.1 Definition 1.2 Examples 1.3 Notation 1.4 Defining Relations 1.5 More Examples 2.Visualization Tool 2.1 Arrow Diagram 2.2 2-D Cartesian Plane 2.3 Graphs 3.Operations of Relations 3.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 Relations 4.1 Reflexive 4.2 Symmetric 4.3 Anti-Symmetric 4.4 Transitive 4.5 Proofs 5.Summary

27 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 R 1 and R 2 are relations from A to B, then R 1  R 2 R 1  R 2 R 1 – R 2 are relations from A to B.

28 28 3. Operations on Relations 3.1: Relations are sets (of ordered pairs). Q: How does R 1  R 2 look like? Skill: You must learn to imagine… Arrow Diagram: R1R1 1 2 3 4 1 2 3 4 {(1,1),(1,3), (3,2),(4,4)} R2R2 1 2 3 4 1 2 3 4 {(1,2),(2,2),(4,4)} R 1  R 2 1 2 3 4 1 2 3 4 {(1,1),(1,2),(1,3),…}

29 29 3. Operations on Relations 3.1: Relations are sets (of ordered pairs). Q: How does R 1  R 2 look like? Skill: You must learn to imagine… 2-D Cartesian Plane: R1R1 R2R2 R 1  R 2 {(1,2),(2,2),(4,4)} {(1,1),(1,3), (3,2),(4,4)} {(1,1),(1,2),(1,3),…}

30 30 3. Operations on Relations 3.1: Relations are sets (of ordered pairs). Q: How does R 1  R 2 look like? Skill: You must learn to imagine… Graphs: R1R1 R2R2 R 1  R 2 {(1,2),(2,2),(4,4)} {(1,1),(1,3), (3,2),(4,4)} {(1,1),(1,2),(1,3),…} 12 34 12 34 12 34

31 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 R 1  R 2 like?” Now, you do it! Imagine and think… Q: How will R 1  R 2 look like? Q: How will R 1 – R 2 look like?

32 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.

33 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 AB R R  {(1,a),(1,b),(3,b)}

34 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 AB R  {(1,a),(1,b),(3,b)} A  B  {(1,a),(1,b),(2,a), (2,b),(3,a),(3,b)} ABAB

35 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 ABR R  {(1,a),(1,b),(3,b)} A  B  {(1,a),(1,b),(2,a), (2,b),(3,a),(3,b)} (A  B)  R  {(2,a), (2,b), (3,b)}

36 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?

37 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

38 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 ABR R  {(1,a),(1,b),(3,b)}

39 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 ABR -1 R  {(1,a),(1,b),(3,b)} R -1  {(a,1),(b,1),(b,3)}

40 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?

41 41 3. Operations on Relations 3.4:Given 2 relations R 1 from A to B and R 2 from B to C, The composition of the relation R 1 and R 2 is defined as follows: R 2 o R 1  {(x,y) |  k, (x,k)  R 1  (k,y)  R 2 } (x,y)  R 2 o R 1 iff  k, (x,k)  R 1  (k,y)  R 2 1 2 3 A 7 5 3 C a b B d c R2R2 R1R1 1 2 37 5 3 AC R 2 o R 1

42 42 3. Operations on Relations 3.4:Given 2 relations R 1 from A to B and R 2 from B to C, The composition of the relation R 1 and R 2 is defined as follows: R 2 o R 1  {(x,y) |  k, (x,k)  R 1  (k,y)  R 2 } (x,y)  R 2 o R 1 iff  k, (x,k)  R 1  (k,y)  R 2 1 2 3 a b AB 7 5 3 C 1 2 37 5 3 AC R 2 o R 1 R1R1 R2R2 d c

43 43 3. Operations on Relations 3.4:Given 2 relations R 1 from A to B and R 2 from B to C, The composition of the relation R 1 and R 2 is defined as follows: R 2 o R 1  {(x,y) |  k, (x,k)  R 1  (k,y)  R 2 } (x,y)  R 2 o R 1 iff  k, (x,k)  R 1  (k,y)  R 2 1 2 3 a b AB 7 5 3 C 1 2 37 5 3 AC R 2 o R 1 R1R1 R2R2 d c

44 44 3. Operations on Relations 3.4:Given 2 relations R 1 from A to B and R 2 from B to C, The composition of the relation R 1 and R 2 is defined as follows: R 2 o R 1  {(x,y) |  k, (x,k)  R 1  (k,y)  R 2 } (x,y)  R 2 o R 1 iff  k, (x,k)  R 1  (k,y)  R 2 How would composition of two relations look like on the … (a) 2D Cartesian drawing? (b) graph drawing? You try to imagine and see…

45 45 3. Operations on Relations 3.5Examples: 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, where S  {(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 R 1 3 5 a b R 10 12 S a b a b S 10 12 (Don’t forget to give the final listing.)

46 46 3. Operations on Relations 3.5Examples: 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, where S  {(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!

47 47 3. Operations on Relations 3.5Examples: 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, where S  {(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.

48 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…

49 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!

50 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!

51 51 Overview 0.Motivation 1.Relations 1.1 Definition 1.2 Examples 1.3 Notation 1.4 Defining Relations 1.5 More Examples 2.Visualization Tool 2.1 Arrow Diagram 2.2 2-D Cartesian Plane 2.3 Graphs 3.Operations of Relations 3.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 Relations 4.1 Reflexive 4.2 Symmetric 4.3 Anti-Symmetric 4.4 Transitive 4.5 Proofs 5.Summary

52 52 4. Properties of Relations ON a set n Common properties for relations on a set: –Reflexive –Symmetric –Anti-Symmetric –Transitive

53 53 4. Relations on a Set – Reflexive 4.1 Definition: Let R be a relation on a set A. R is reflexive iff  x  A, 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.

54 54 4. Relations on a Set – Reflexive 4.1 Definition: Let R be a relation on a set A. R is reflexive iff  x  A, x R x How does the property look like in a diagram? x x RA A

55 55 4. Relations on a Set – Symmetric 4.2 Definition: Let R be a relation on a set A. R is symmetric iff  x,y  A, 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.

56 56 4. Relations on a Set – Symmetric 4.2 Definition: Let R be a relation on a set A. R is symmetric iff  x,y  A, x R y  y R x How does the property look like in a diagram? x y RA A y x R

57 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,y  A, 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.

58 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,y  A, x R y  y R x  x=y How does the property look like in a diagram? x y RA A y x R

59 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,z  A, 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.

60 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,z  A, x R y  y R z  x R z How does the property look like in a diagram? x y RA A y z R      

61 61 Note: n ‘Anti-symmetric’ is different from ‘not symmetric’. Pay attention to the defn: R is symmetric iff  x,y  A, x R y  y R x R is anti-symmetric iff  x,y  A, 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)}

62 62 4.5 Proofs n Proving properties: Look at definition! –Reflexive  x  A, (x,x)  R –Symmetric  x,y  A, x R y  y R x –Anti-Symmetric  x,y  A, x R y  y R x  x  y –Transitive  x,y,z  A, x R y  y R z  x R z

63 63 Expectation required of students (II) n 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. n This is applicable to all future topics.

64 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.

65 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)

66 66 4.5 Proofs n 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)

67 67 4.5 Proofs 4.5.4 Prove or disprove: R  R -1 is always anti-symmetric for any relation R. n Is it true… or is it false? n 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…

68 68 4.5 Proofs Lesson: n Explore using examples –Try simple ones first –Try a few examples –Try a variety of examples.

69 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 -1 R Hmmm… so far it is true… try another one.

70 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? RR -1

71 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.

72 72 4.5 Proofs n 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)

73 73 5. Summary n Axiomatic Definitions: –Relation from A to B : R  A  B –Relation on A : R  A  A or R  A 2 –Complemention: (x,y)  R iff (x,y)  (A  B) – R –Inverse: (y,x)  R -1 iff (x,y)  R –Composition: (x,y)  R 2 o R 1 iff  k, (x,k)  R 1  (k,y)  R 2 –Reflexive:  x  A, (x,x)  R –Symmetric:  x,y  A, x R y  y R x –Anti-Symmetric:  x,y  A, x R y  y R x  x = y –Transitive:  x,y,z  A, x R y  y R z  x R z

74 74 5. Summary Skills: n 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. n 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.

75 75 n Concept of relations are used in Relational Databases n 2 Important operations are used in RDBMS: Joins (a more generalised way to define cartesian product), and Projections.

76 76 NameM# CseCde NameM#CseCde Join

77 77 NameM# Name Projection

78 78 n End of lecture.


Download ppt "1 Lecture 2: Relations Relations Reading: Epp Chp 10.1, 10.2."

Similar presentations


Ads by Google