1 / 30

Discrete Mathematics 6 th edition, 2005

Discrete Mathematics 6 th edition, 2005. Chapter 3 Relations. Relations Equivalence Relations Matrices of Relations Relational Database*. 3.1 Relations. Given two sets X and Y its Cartesian product X  Y is the set of all ordered pairs ( x , y ) where x  X and y  Y

Download Presentation

Discrete Mathematics 6 th edition, 2005

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. Discrete Mathematics6th edition, 2005 Chapter 3 Relations • Relations • Equivalence Relations • Matrices of Relations • Relational Database*

  2. 3.1 Relations • Given two sets X and Y its Cartesian productXY is the set of all ordered pairs (x,y) where xX and yY • In symbols XY = {(x, y) | xX and yY} • A binary relationR from a set X to a set Y is a subset of the Cartesian product XY • Example: X = {1, 2, 3} and Y = {a, b} • R= {(1,a), (1,b), (2,b), (3,a)} is a relation between X and Y

  3. Domain and range Given a relation R from X to Y, • The domain of R is the set • Dom(R) = { xX | (x, y) R for some yY} • The range of R is the set • Rng(R) = { yY | (x, y) R for some x X} • Example: • if X = {1, 2, 3} and Y = {a, b} • R = {(1,a), (1,b), (2,b)} • Then: Dom(R)= {1, 2}, Rng(R) = {a, b}

  4. Example of a relation • Let X = {1, 2, 3} and Y = {a, b, c, d}. • Define R = {(1,a), (1,d), (2,a), (2,b), (2,c)} • The relation can be pictured by a graph:

  5. 1 2 3 4 A digraph of a relation R = {(x, y)| x≤y, x, y in X}, X = {1, 2, 3, 4} R = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)}

  6. Properties of relations Let R be a relation on a set X i.e. R is a subset of the Cartesian product XX • R is reflexive if (x,x) R for every xX • R is symmetric if for all x, y X such that (x,y) R then (y,x) R • R is transitive if (x,y) R and (y,z) R imply (x,z) R • R is antisymmetric if for all x,yX such that xy, (x,y)R then (y,x)R

  7. Order relations Let X be a set and R a relation on X. R is a partial order on X if R is reflexive, antisymmetric and transitive. Let x,yX • If (x,y) or (y,x) are in R, then x and y are comparable • If (x,y) R and (y,x) R then x and y are incomparable If every pair of elements in X are comparable, then R is atotal order on X Ex) (x, y) in R if x divides y, x and y are positive integers. Ex) (x, y) in R if xy, x and y are positive integers.

  8. Inverse of a relation Given a relation R from X to Y, its inverseR-1 is the relation from Y to X defined by R-1 = { (y,x) | (x,y)  R } • Example: if R = {(1,a), (1,d), (2,a), (2,b), (2,c)} then R-1= {(a,1), (d,1), (a,2), (b,2), (c,2)}

  9. Composition of relation • composition • R1 : relation from X to Y • R2 : relation from Y to Z • R2 R1 • composition of R1 and R2 • the relation from X to Z • R2 R1 = {(x,z) | (x,y)R1 and (y,z)R2 for some yY}

  10. 3.2 Equivalence relations Let X be a set and R a relation on X • R is an equivalence relation on X R is reflexive, symmetric and transitive. • Example: • Let X = {integers} and R be the relation on X defined by: xRy x - y = 5k, for some integer k • It is easy to show that R is an equivalence relation on the set of integers.

  11. f c d a b h e g i Example • Relation R on XX = {a, b, c, d, e, f, g, h, i}F1 = {a, c, e},F2 = {b},F3={d, f, g, h, i}

  12. Partitions • A partitionS on a set X is a family {A1, A2,…, An} of subsets of X, such that • A1A2A3…An = X • Aj Ak =  for every j, k with j  k, 1 <j, k<n. • Example: if X = {integers}, E = {even integers) and O = {odd integers}, then S = {E, O} is a partition of X.

  13. Partitions and equivalence relations Theorem 3.2.1: Let S bea partition on a set X. Define a relation R on X by xRy if x, y are in the same set T for T S. Then R is an equivalence relation on X. i.e. an equivalence relation on a set X corresponds to a partition of X and conversely.

  14. Equivalence classes Let X be a set and let R be an equivalence relation on X. Let a X. • Define [a] ={ xX| xRa } • Let S= { [a] | a X } Theorem 3.2.8: S is a partition on X. • The sets [a] are called equivalence classes of X induced by the relation R. • Given a, b  X, then [a] = [b] or [a][b] = 

  15. [a] [g] f c d b a e g a h e aRe^eRa eRg^gRe g ? i aRg gRa [a] = [g] Example (([a][g])  ([a][g])?) • Equivalence relation R on XX = {a, b, c, d, e, f, g, h, i}F1 = {a, c, e}, F2 = {b}, F3={e, d, f, g, h, i}

  16. Set of equivalence classes If R is an equivalence relation on a set X, define X/R = {[a] | a X }. Theorem 3.2.15: If each equivalence class on a finite set X has k elements, then X/R has |X|/k elements, i.e. |X/R| = |X| / k.

  17. 3.3 Matrices of relations • Let X, Y be sets and R a relation from X to Y • Write the matrix A = (aij) of the relation as follows: • Rows of A = elements of X • Columns of A = elements of Y • Element ai,j = 0 • if the element of X in row i and the element of Y in column j are not related • Element ai,j = 1 • if the element of X in row i and the element of Y in column j are related

  18. The matrix of a relation (1) Example: Let X = {1, 2, 3}, Y = {a, b, c, d} Let R = {(1,a), (1,d), (2,a), (2,b), (2,c)} The matrix A of the relation R is A =

  19. The matrix of a relation (2) • If R is a relation from a set X to itself and A is the matrix of R then A is a square matrix. • Example • Let X = {a, b, c, d} and • R = {(a,a), (b,b), (c,c), (d,d), (b,c), (c,b)}. • Then A =

  20. j B m개 m개 A C Ci,j i i j The product of matrices • Let A be the (lm) matrix of R1 and let B be the (mn) matrix of R2 • The ij-th element of the product of these matrices, AB, is computed as • 1 : if • 0 : if

  21. The matrix of a composed relation Theorem 3.3.6: • Let R1 be a relation from X to Y and let R2 be a relation from Y to Z. • Choose orderings of X, Y, and Z. • Let A1 be the matrix of R1 and let A2 be the matrix of R2 with respect to the orderings selected. • The matrix of the relation R2 R1 with respect to the orderings selected is obtained by replacing each nonzero terms in the matrix product A1A2 by 1

  22. The matrix of a relation on a set X Let A be the square matrix of a relation R from X to itself. Let A2 = the matrix product AA. • R is reflexive All terms aii in the main diagonal of A are 1. • R is symmetric  aij = aji for all i and j, • i.e. R is a symmetric relation on X if A is a symmetric matrix • R istransitive  whenever cij in C = A2 is nonzero then entry aij in A is also nonzero.

  23. 3.4 Relational databases • A binaryrelation R is a relation among two sets X and Y, already defined as R X  Y. • An n-ary relation R is a relation among n sets X1, X2,…, Xn, i.e. a subset of the Cartesian product, RX1 X2  … Xn. • Thus, R is a set of n-tuples (x1, x2,…, xn) where xk Xk, 1 <k<n.

  24. Databases • A database is a collection of records that are manipulated by a computer. They can be considered as n sets X1 through Xn, each of which contains a list of items with information. • Database management systems are programs that help access and manipulate information stored in databases.

  25. Relational database model • Columns of an n-ary relation are called attributes • Anattribute is akeyif no two entries have the same value • e.g. social security number • A query is a request for information from the database

  26. Relational databases model • Table PLAYER • 4-ary relation X1X2X3X4 ID Number 22012 93831 58199 84341 01180 26710 61049 39826 Name Johnsonbaugh Glover Battey Cage Homer Score Johnsonbaugh Singleton Position c of p c 1b p of 2b Age 22 24 18 30 37 22 30 31 key (uniquely defines an n-tuple)

  27. Operators • The selection operator chooses n-tuples from a relation by giving conditions on the attributes • The projection operator chooses two or more columns and eliminates duplicates • The join operator manipulates two relations

  28. ID Number 22012 93831 58199 84341 01180 26710 61049 39826 Name Johnsonbaugh Glover Battey Cage Homer Score Johnsonbaugh Singleton Position c of p c 1b p of 2b Age 22 24 18 30 37 22 30 31 Operator - select <PLAYER> PLAYER[Position=c] (22012, Johnsonbaugh, c, 22) , (84341, Cage, c, 30)

  29. ID Number 22012 93831 58199 84341 01180 26710 61049 39826 Name Johnsonbaugh Glover Battey Cage Homer Score Johnsonbaugh Singleton Position c of p c 1b p of 2b Age 22 24 18 30 37 22 30 31 Operator - project <PLAYER> PLAYER[Name, Position] (Johnsonbaugh, c), (Glover,of), (Battey, p), (Cage, c), (Homer, 1b), (Score, p), (Johnsonbaugh, of), (Singleton, 2b)

  30. <ASSIGNMENT> PID 39826 26710 58199 01180 Team Blue Sox Mutts Jackalopes Mutts ID Number 22012 93831 58199 84341 01180 26710 61049 39826 Name Johnsonbaugh Glover Battey Cage Homer Score Johnsonbaugh Singleton Position c of p c 1b p of 2b Age 22 24 18 30 37 22 30 31 Operator - join <PLAYER> PLAYER[ID Number = PID] ASSIGNMENT <PLAYER[ID Number = PID] ASSIGNMENT> ID Number 58199 01180 26710 39826 Name Battey Homer Score Singleton Position p 1b p 2b Age 18 37 22 31 Team Jackalopes Mutts Mutts Blue Sox

More Related