1 / 90

Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

King ABDUL AZIZ University Faculty Of Computing and Information Technology. CPCS 222 Discrete Structures I Relations. Dr. Eng. Farag Elnagahy farahelnagahy@hotmail.com Office Phone: 67967. Relations. Functions as Relations Let A and B be nonempty sets.

maree
Download Presentation

Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. King ABDUL AZIZ UniversityFaculty Of Computing and Information Technology CPCS 222 Discrete Structures I Relations Dr. Eng. Farag Elnagahy farahelnagahy@hotmail.com Office Phone: 67967

  2. Relations Functions as Relations • Let A and B be nonempty sets. A functionf from A to B is an assignment of exactly one element of B to each element of A. We write f(a) = b if b is the unique element of B assigned by the function f to the element a of A. If f is a function from A to B, we write f : A → B Relations are a generalization of function

  3. Relations binary relation Let A, B be sets, a binary relationR from A to B, is a subset of A×B. R  AxB A binary relation from A to B is a set R of ordered pairs where the first element of each ordered pairs comes from A and the second element comes from B. R:A×B, or R:A,Bis a subset of the set A×B. The notation aRb means that (a,b)R. The notation aRb means that (a,b)R. When (a,b) belongs to R , a is said to be related to b by relation R.

  4. Relations binary relation • Example • Let A be the set ofstudents in your school and • let B be set of courses, and • let R be the relation that consists of those pairs • (a,b), where a is a student enrolled in courseb. • If Ahmed, Ali, and Mohamed are enrolled in CP223 and Ahmed, Ali, and Osman are enrolled in CS313 • Then the pairs (Ahmed,CP223), (Ali, CP223), (Mohamed, CP223), (Ahmed, CS313), (Ali, CS313 ), and (Osman, CS313) belong to (are in) R. • The pair (Osman, CP223) is not in R.

  5. Relations Representation of relation (Arrow diagram & table) Example Let A ={0,1,2} and B={a,b} and the relation R from A to B is {(0,a),(0,b),(1,a),(2,b)}. 0 a 1 b 2 Arrow diagram table 0 R a 0 R b 1 R a 2 R b 1 R b 2 R a

  6. a Relations Representation of relation (digraphs) A directed graph, or digraph consists of a set V of vertices (or nodes) together with a set E of ordered pairs of elements of V called edges (or arcs). The vertexa is called the initial vertex of the edge (a,b), and vertexb is called the terminal vertex of this edge. ab An edge of the form (a,a) is represented by an arc from the vertex a back to itself and it is called a loop. edge or arc

  7. 1 2 3 4 Relations Representation of relation (digraphs) Example R={(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3), (3,4),(4,4)} loop vertex(node) edge(arc) A directed graph (digraph)

  8. MR= Relations Representation of relation (matrix) A relation between finite sets can be represented using a zero-onematrix. Suppose that R is a relation from A={a1,a2,…,am) to B={b1,b2,….,bn}. This relation can be represented by the matrix MR=[mij], where: [mij]= 1 if (ai,bj)  R 0 if (ai,bj)  R ExampleLet A ={0,1,2} and B={a,b} and the relation R from A to B is {(0,a),(0,b),(1,a),(2,b)}.

  9. Relations on a Set • A (binary) relation from a set A to itself is called a relation on the set A. • Example • Let A={1,2,3,4} which ordered pairs are in the R={(a,b) | adividesb}. • 1,2,3,4 are positive integer, max is 4 • R= {(1,1),(1,2),(1,3),(1,4),(2,2),(2,4), • (3,3),(4,4)} • Draw the arrow diagram, digraph, • and matrix?

  10. Relations on a Set Example Consider 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} R4={(a,b) | a=b} R5={(a,b) | a=b+1} R6={(a,b) | a+b  3} Which of these relations contain each of the pairs (1,1), (1,2), (2,1), (1,-1), and (2,2) ? The pair (1,1) is in ….. …..

  11. Relations on a Set How many relations are there on a set with n elements? A relation on a set A is a subset of AxA. AxA has n2elements when A has n elements, and a set with m elements has 2m subsets, there are 2n2 subsets of AxA. Thus there are 2n2 relationson a set with n elements. For example there are 232 = 29 =512 relationson the set {a,b,c}

  12. Properties of Relations There are several properties that are used to classify relations on a set. In some relations an element is always relatedto itself. For example, let R be the relation on the set of all people consisting of pairs (x,y) where x and y has the same father and the same mother. Then xRx for every person x.

  13. Properties of Relations • A relation R on a set A is called reflexive if (a,a)R for every element aA (aA), aRa. • E.g., the relation≥ :≡ {(a,b) | a≥b}is reflexive • A relation R on the set A is reflexive if a((a,a)R) when the universe of discourse is the set of all elements in A. Reflexive means that every member is related to itself. • A relation R on a set A is called irreflexive if (a,a)  R for every element in A There is no element in A is related to itself

  14. Properties of Relations Example Consider the following relations on the {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),(3,4)} R5={(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3), (3,4),(4,4)} R6={(3,4)} Which of these relations are reflexive? The relations R3 and R5 are reflexive because they both contain all pairs of the form (a,a). irreflexive ?

  15. Properties of Relations Example Consider the following relations on the set of integers 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 relations are reflexive? The relations R1 , R3 and R4 are reflexive because they both contain all pairs of the form (a,a). irreflexive ?

  16. Properties of Relations • Example • Is the “divides” relation on the set of positive integersreflexive? • Is the “divides” relation on the set of integersreflexive? • Note that 0 does not divide 0.

  17. 1 2 3 4 Properties of Relations A relation R on a set A is called reflexive if and only if there is a loop at every vertex of the directed graph. R={(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3), (3,4),(4,4)} irreflexive ?

  18. Properties of Relations A relation R on a set A is called reflexive if and only if (ai,ai)R this means that mii=1 for i=1,2,.,n All the elements on the main diagonal of MR are equal to 1 R={(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3), (3,4),(4,4)} MR= irreflexive ?

  19. Properties of Relations • A relation R on a set A is symmetric if (b,a)R whenever(a,b)R for all a,b A ab((a,b) R → (b,a)R ) • A relation R on a set A is antisymmetric if (a,b)R and(b,a)R then a=b for all a,b A ab((a,b) R  (b,a)R→ (a=b)) Note that “the termsymmetricandantisymmetricare not opposites, the relation can have both of these properties or may lack both of them”

  20. Properties of Relations A relation cannot be bothsymmetric and antisymmetric if it contains some pair of the form (a,b), where a≠b example Let R be the following relation defined on the set {a, b, c, d}: R = {(a, a), (a, c), (a, d), (b, a), (b, b), (b, c), (b, d), (c, b), (c, c), (d, b), (d, d)}. Determine whether R is: reflexive. Yes symmetric. No there is no (c,a) for example antisymmetric. No b  c b  d

  21. Properties of Relations A relation cannot be bothsymmetric and antisymmetric if it contains some pair of the form (a,b), where a≠b example Let R be the following relation defined on the set {a, b, c, d}: R = {(a, a), (b, b), (c, c), (d, d)}. Determine whether R is: reflexive. Yes symmetric. yes antisymmetric. yes

  22. Properties of Relations Example Consider the following relations on the {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),(3,4)} R5={(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3), (3,4),(4,4)} R6={(3,4)} Which of these relations are symmetric and which are antisymmetric ? R2andR3are symmetric because in each case (b,a) belongs to the relation whenever (a,b) does.

  23. Properties of Relations Example Consider the following relations on the set of integers 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 relations are symmetric and which are antisymmetric ? R3 , R4 ,andR6are symmetric because in each case (b,a) belongs to the relation whenever (a,b) does.

  24. Properties of Relations Example Consider the following relations on the set of integers R1={(a,b) | a  b} ab and ba imply that 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} R1 , R2 , R4 , R5are antisymmetric R2 is antisymmetric it is impossible for a>b and b>a R5 is antisymmetric it is impossible for a=b+1 and b=a+1

  25. Properties of Relations Example Is the “divides” relation on the set of positive integerssymmetric? Is it antisymmetric ? This relation is not symmetric because 1|2, but 2|1. It is antisymmetric because a|b, and b|a then a=b.

  26. Properties of Relations A relation R on a set A is called symmetric if and only if for every edge between distinct vertices in its directed graph there is an edge in the opposite direction. R={(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3), (3,4),(4,4)} 2 1 Not symmetric 3 4

  27. Properties of Relations A relation R on a set A is called antisymmetric if and only if there are never two edges in the opposite direction between distinct vertices in its directed graph 2 1 Antisymmetric Not reflexive Not symmetric 3 4

  28. Properties of Relations A relation R on a set A is called symmetric if and only if mij=mji of MR for i=1,2,.,n j=1,2,.,n R={(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3), (3,4),(4,4)} (a,b) MR= Antisymmetric

  29. Properties of Relations A relation R on a set A is called symmetric if and only if mij=mji of MR for i=1,2,.,n j=1,2,.,n R={(1,1),(1,2),(1,3),(2,2),(2,3),(2,4),(3,3), (3,4),(4,4)} (a,b) MR= Antisymmetric

  30. Properties of Relations Suppose that the relation R on a set A is represented by the matrix A relation R is reflexive iff (ai,ai)R this means that mii=1 for i=1,2,.,n MR= A relation R is symmetric if (a,b)R ↔ (b,a)R this means that mij=mji for i=1,2,.,n MR=

  31. Properties of Relations Suppose that the relation R on a set A is represented by the matrix This relation is reflexive symmetric antisymmetric MR= MR= This relation is reflexive symmetric antisymmetric

  32. Properties of Relations Suppose that the relation R on a set A is represented by the matrix This relation is reflexive symmetric antisymmetric MR= MR= This relation is reflexivesymmetric antisymmetric

  33. Properties of Relations Let R be the relation consisting of all pairs (x,y) of students at your school, where x has taken more credits than y. Suppose that x is related to y and y related to z. This means that x has taken more credits than y and y has taken more credits than z We can conclude that x has taken more credits than z, so that x is related to z. The relation R has the transitive property.

  34. Properties of Relations A relation R on a set A is called transitive if whenever (a,b)R and (b,c)R then (a,c)R , for all a, b, c  Aabc(( (a,b)R  (b,c)R) → (a,c)R)

  35. Properties of Relations • Consider the following relations on the {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={(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3), • (3,4),(4,4)} • R6={(3,4)} • Which of these relations are transitive ? • The relation is transitive If (a,b) and (b,c) belong to the relation then (a,c) also does. • R4 (3,2),(2,1),(3,1) (4,2) (2,1),(4,1) • (4,3) (3,1),(4,1) (4,3) (3,2),(4,2)

  36. Properties of Relations • Consider the following relations on the set of integers • 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 relations are transitive ? • The relation is transitive If (a,b) and (b,c) belong to the relation then (a,c) also does.

  37. Properties of Relations Is the “divides” relation on the set of positive integerstransitive? Suppose that a divides b and b divides c. Then there are positive integers k and l such that b=ak and c=bl. Hence, c=a(kl), so a divides c. It follows that the relation is transitive

  38. Properties of Relations A relation is transitive if and only if whenever there is an edge from a vertex x to a vertex y and an edge from a vertex y to a vertex z, there is an edge from a vertex x to a vertex z completing a triangle where each side is a directed edge with the correct direction. 2 1 3 4

  39. Properties of Relations Exercises PP.542-544 2-3 13-14 22-28 32

  40. Combining Relations Let A={1,2,3} and B={1,2,3,4} The relation R1={(1,1),(2,2),(3,3)} R2={(1,1),(1,2),(1,3),(1,4)} R1 R2 = {(1,1),(1,2),(1,3),(1,4),(2,2),(3,3)} R1  R2 = {(1,1)} R1 - R2 = {(2,2),(3,3)} R2 - R1 = {(1,2),(1,3),(1,4)} R1  R2 = R2  R1 = R1 R2- R1  R2 = {(1,2),(1,3),(1,4),(2,2),(3,3)} Read examples 18,19 PP. 525-526

  41. Combining Relations Let A={1,2,3} and B={1,2,3,4} The relation R1={(1,1),(2,2),(3,3)} R2={(1,1),(1,2),(1,3),(1,4)} Construct MR1 andMR2 R1 R2 = MR1R2 = MR1 MR2 R1  R2 = MR1R2 = MR1 MR2

  42. Compositions of Relations Let R be a relation from a set A to a set B and S a relation from B to a set C. The composite of R and S is the relation consisting of ordered pairs (a,c), where aA , cC, and for which there exists an element bB such that (a,b)R and (b,c)S. we denote the composite of R and S by SR Example R is the relation from {1,2,3} to {1,2,3,4} S is the relation from {1,2,3,4} to {0,1,2} R= {(1,1),(1,4),(2,3),(3,1),(3,4)} S= {(1,0),(2,0),(3,1),(3,2),(4,1)} SR={(1,0),(1,1),(2,1),(2,2),(3,0),(3,1)}} T/F

  43. Compositions of Relations To find the matrix representing the relation SR (composite of R and S) Construct MRandMs Then calculate the Boolean product (⊙) of the matrix MRandMs MSR= MR⊙Ms

  44. Compositions of Relations • The nthpowerRn of a relation R on a set A can be defined recursively by:R1 =RRn+1 = RnR for all n>0. • R2= RR , R3= R2R= (RR)R • Example • R= {(1,1),(2,1),(3,2),(4,3)}, find the powers Rn,n=2,3,4,…. • R2= RR= {(1,1),(2,1),(3,1),(4,2)} • R3= R2R= {(1,1),(2,1),(3,1),(4,1)} • R4= R3R= {(1,1),(2,1),(3,1),(4,1)}= R3 • Rn=R3

  45. Compositions of Relations Let R be a relation from a set A to a set B, • The inverse relation (R-1) from B to A is the set of ordered pairs {(b,a) | (a,b)  R } • The complement relation R is the set of ordered pairs {(a,b) | (a,b)  R } • Exercises PP. 527-529 • 1-7 , 24-25 , 32 , 54

  46. Closures of Relations Consider relation R={(1,2),(2,2),(3,3)} on the set A = {1,2,3,4}. Is R reflexive? No What can we add to R to make it reflexive? (1,1), (4,4) R’ = R U {(1,1),(4,4)} is called the reflexive closure of R.

  47. Closures of Relations • In general • Let R be a relation on a set A • R may or may not have some property P such as: • Reflexivity – Symmetry – Transitivity • The closure of relation R on set A with respect to property P is the relation R’ with • R  R’ • R’ has property P • R’ is called the closure of R with respect to P

  48. Closures of Relations Let R be the relation on {1, 2, 3, 4} such that R = {(1, 1), (1, 4), (2, 3), (3, 1), (3, 3), (4, 4)}. Find: (a) the reflexive closure of R. (b) the symmetric closure of R. (c) the transitive closure of R. (a) {(1,1), (1,4), (2,2), (2,3), (3,1), (3,3), (4,4)}. (b) {(1,1), (1,3), (1,4), (2,3), (3,1), (3,2), (3,3), (4,1), (4,4)}. (c) {(1,1), (1,4), (2,1), (2,3), (2,4), (3,1), (3,3), (3,4), (4,4)}. Read examples 1 and 2 PP. 454

  49. Equivalence Relations A relation on a set A is called equivalence relation if it is reflexive, symmetric, and transitive. Two elements a and b that related by an equivalence relation are called equivalent. a ~ b Is R is equivalence relation? R={(a,b) | a=b or a=-b} r,s, and t Read examples 2,4,5,6,7 PP. 556-557 Exercises PP.553-554 1,3, 5-7 Exercises PP.562-563 1-2

  50. Equivalence Relations Congruence Modulo m Let m be a positive integer m>1 . Show that the following relation is an equivalence relation on the set of integers. R={ (a,b) | ab(mod m) } Note that ab(mod m) Meansm divides a-b • a-a=0 and is divisible by m ( R is reflexive ) • ab(mod m) then a-b=km where k is an integer It follows that b-a=(-k)m means ba(mod m) ( R is symmetric ) • suppose that ab(mod m) and bc(mod m) a-b=km and b-c=lm add both equations we get: a-b+ b-c= km+ lm=(k+l)m a-c=(k+l)m I.e ac(mod m) ( R is transitive ) R is equivalence relation

More Related