1 / 37

Chapter 5 Relations and Functions

Discrete and Combinatorial Mathematics R. P. Grimaldi , 5 th edition, 2004. Chapter 5 Relations and Functions. Relations. For sets A and B, its Cartesian product ( cross product ) is the set of all ordered pairs (a,b) where a  A and b  B. In symbols A  B = {(a, b) | a  A and b  B}

tassos
Télécharger la présentation

Chapter 5 Relations and Functions

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 and Combinatorial MathematicsR. P. Grimaldi,5th edition, 2004 Chapter 5 Relations and Functions

  2. Relations For sets A and B, its Cartesian product (cross product) is the set of all ordered pairs (a,b) where aA and bB. • In symbols AB = {(a, b) | aA and bB} • Example: A = {1, 2, 3} and B = {a, b} AB = {(1,a),(1,b),(2,a),(2,b),(3,a),(3,b)}, A = . For sets A and B, any subset of AB is called a binary relation from A to B. • R = {(1,a), (1,b), (2,b), (3,a)} is a relation from A to B. • (1,a)R also denotes 1Ra. For finite sets A and B with |A| = m and |B| = n, there are 2mn relations from A to B, including the empty relation and the relation AB itself.

  3. Product on Set Operations Theorem 5.1 For any sets A, B, C   : (a) A  (B  C) = (A  B)  (A  C) (b) A  (B  C) = (A  B)  (A  C) (c) (A  B)  C = (A  C)  (B  C) (d) (A  B)  C = (A  C)  (B  C) Proof of (a). (a,b)A  (B  C)  aA and bB  C  aA and bB and bC  (aA and bB) and (aA and bC)  (a,b)A  B and (a,b)A  C  (a,b)(A  B)  (A  C) #

  4. Properties of Relations Let R be a relation on a set A, i.e., R is a subset of the Cartesian product AA. • R is reflexive(反身) if (x,x)R, for all xA • A = {1,2,3} reflexive: R = {(1,1),(2,2),(3,3)} not reflexive: R = {(1,1),(1,2),(2,2),(2,3)} • R is symmetric(對稱) if (x,y)R  (y,x) R, for all x, yA • A = {1,2,3} symmetric: R = {(1,2),(2,1),(3,3)} not symmetric: R = {(1,1),(1,2),(2,2)}

  5. Properties of Relations (cont.) • R is transitive(遞移) if (x,y)R and (y,z)R  (x,z) R • A = {1,2,3} transitive: R = {(1,2),(2,3),(1,3),(3,1),(2,1),(1,1),(2,2),(3,2),(3,3)} not transitive: R = {(1,2),(2,3),(3,3)} • R is antisymmetric(反對稱) if for all x,yX such that xy, if (x,y) R  (y,x) R • A = {1,2,3} antisymmetric: R = {(1,2),(2,3),(1,3),(1,1)} not antisymmetric: R = {(1,2),(2,1),(3,3)}

  6. Relation Matrices Let X, Y be sets and R a relation from X to Y • Write the matrix M = (mij) of the relation as follows: • Rows of M = elements of X • Columns of M = elements of Y • Element mi,j = 0 if the element of X in row i and the element of Y in column j are not related • Element mi,j = 1 if the element of X in row i and the element of Y in column j are related

  7. 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 M of the relation R is M =

  8. Matrices • Let E = (eij)mn, F = (fij)mn be two mn (0,1)-matrices. We say E  F if eij  fij for all i,j. • For nZ+, (0,1)-matrix In = (ij)nn where ij = 1 if i = j, otherwise ij = 0. • Let A = (aij)mn be a (0,1)-matrix. The transpose of A, denoted by Atr, is the matrix (a*ji)nm where a*ji = aij for all i,j.

  9. Properties of Relation Matrices Theorem 7.2 Given a set A with |A| = n and a relation R on A, Let M denote the relation matrix for R. Then (a) R is reflexiveiff In  M; (All terms mii in the main diagonal of M are 1.) (b) R is symmetric iff M = Mtr. (aij = aji for all i and j.) (c) R is transitive iff M2  M. (cij in M2 is nonzero then entry mij in M is also nonzero.) (d) R is antisymmetric iff MMtr  In.

  10. Property (c) M = M2= • M232 0 •  m31m12+m32m22+m33m32+m34m42  0 • There exists k such thatm3kmk2  0 m3k  0andmk2  0m32 0. #

  11. 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. (e.g. “”) LetR be a partial order on X. • R is atotal order (linear order) on X if every pair of elements x,yX satisfies xRy or yRx. (e.g. topological sorting)

  12. Topological Sorting a d  c a b c d e b e

  13. Inverse of a Relation Given a relation R from X to Y, its inverse R-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)}

  14. Equivalence Relations Let X be a set and R a relation on X. R is an equivalence relation on X ifR is reflexive, symmetric and transitive. (e.g. “=”)

  15. Equivalence Classes Let R be an equivalence relation on a set A. For each x A, the equivalence class of x, denoted by [x] ={ yA | yRx }. Theorem 7.6 If R is an equivalence relation on a set A, and x, y  A, then (a) x  [x]; (b) xRy iff [x] = [y]; and (c) [x] = [y] or [x]∩[y] = .

  16. Proof of Theorem 7.6 • By the reflexive property of R. • () Let w[x]. xRy and wRx  wRy. (R is transitive.)  w[y]  [x]  [y]. R is symmetric  yRx  …  [y]  [x].  [x] = [y]. () Let [x] = [y]. x[x]  x[y]  xRy.

  17. Proof of Theorem 7.6 (cont.) (c) Assume [x]  [y] and [x]∩[y]  . Let v  A with v  [x] and v  [y].  vRx and vRy  xRv and vRy (symmetric)  xRy (transitive)  [x] = [y]. (by (b))  ∴ [x] = [y] or [x]∩[y] = . #

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

  19. Partitions and Equivalence Relations Theorem 7.7 If A is a set, then (a) any equivalence relation R on A induces a partition of A, and (b) any partition of A gives rise to an equivalence relation R on A. Proof. Part (a) follows from (a) and (c) of Theorem 7.6. Part (b): Let S be a partition of A. Define xRy if x, y are in the same set T for TS. Let xA.  x  T for some T  S. ∴xRx and R is reflexive. Suppose xRy.  x,y  T for some T  S. ∴yRx and R is symmetric. Suppose xRy and yRz.  x,y,z  T for some T  S. ∴xRz and R is transitive. #

  20. Functions For nonempty sets X, Y, a function, or mapping, f from X to Y, denoted by f : X  Y, is a relation from X to Y such that if two pairs (x,y) and (x,y’)  f, then y = y’. • Example: Dom(f) = X = {a, b, c, d}, Rng(f) = {1, 3, 5} f(a) = f(b) = 3, f(c) = 5, f(d) = 1.

  21. How many functions? Let X,Y be nonempty sets with |X| = m and |Y| = n. Define the functions with domain X. x1 y1 x2 y2 xm yn For each xi we select one of the n elements of Y.  There are nm functions from X to Y.

  22. One-to-one functions A function f : X  Y is one-to-one, injective  for each y  Y there exists at most one x  X with f(x) = y. Alternative definition: f : X  Y is one-to-one  for each pair of distinct elements x1, x2  X there exist two distinct elements y1, y2  Y such that f(x1) = y1 and f(x2) = y2. Examples: • The function f(x) = 2x from the set of real numbers to itself is one-to-one • The function f : R  R defined by f(x) = x2 is not one-to-one, since for every real number x, f(x) = f(-x).

  23. How many one-to-one functions? Let X,Y be nonempty sets with |X| = m and |Y| = n, where m  n. x1 y1 x2 y2 xm yn There are n choices for x1, n-1 choices for x2, n-2 choices for x3, and so on.  There are P(n,m) one-to-one functions from X to Y.

  24. Onto functions A function f : A  B is onto ,or surjective  for each b  B there exists at least one a  A with f(a) = b, i.e. Rng(f) = B. Example: • The function f: R  R defined by f(x) = x3 is an onto function. • The function g: R  R defined by g(x) = x2 is not an onto function.

  25. How many onto functions? Let X,Y be nonempty sets with |X| = 4 and |Y| = 3. w 1 x 2 y 3 z • There are 34 functions from X to Y. • There are 24 functions from X to {1,2} ({1,3},{2,3}). • The set of these 24 functions contains the functions • from X to {1} and the functions from X to {2}. •  There are C(3,3)34 – C(3,2)24 + C(3,1)14 functions.

  26. How many onto functions? Let X,Y be nonempty sets with |X| = m and |Y| = n. • There are C(n,n)nm – C(n,n-1)(n-1)m + C(n,n-2)(n-2)m – • … + (-1)n-1 C(n,1) 1m = • onto functions from X to Y. Stirling number of the second kind, denoted by S(m,n): The number of ways to distribute the m distinct objects into n identical containers, with no container left empty, is

  27. Bijective functions A function f : X Y is bijective  f is one-to-one and onto. • Examples: • A linear function f(x) = ax + b is a bijective function from the set of real numbers to itself • The function f(x) = x3 is bijective from the set of real numbers to itself. • Question: Let X,Y be nonempty sets with |X| = n and |Y| = n. How many bijective functions are there from X to Y?

  28. Inverse Given a function y = f(x), the inverse f -1 is the set {(y, x) | y = f(x)}. • The inverse f -1 of f is not necessarily a function. • Example: if f(x) = x2, then f -1 (4) = ± 41/2= ± 2, not a unique value and therefore f -1 is not a function. • However, if f is a bijective function, it can be shown that f -1 is a function.

  29. Composite Functions If f : A  B and g : B  C, we define the composite function, denoted by g ◦ f : A  C, by g ◦ f (a) = g(f(a)) for each a  A. • Example: f(x) = x2 -1, g(x) = 3x + 5. Then f ◦ g(x) = f(g(x)) = f(3x + 5) = (3x + 5)2 - 1 • Composite functions are associative: f ◦ (g ◦h) = (f ◦ g) ◦ h, • But, in general, it is not commutative: f ◦ g  g ◦ f.

  30. Binary Operations For any nonempty sets A, B, any function f : A x A  B is called a binary operation on A. If B  A then the binary operation is said to closed (on A). • Examples • The function f : Z x Z  Z, f(a,b) = a – b, is a closed binary operation on Z. • The function g : Z+x Z+ Z, g(a,b) = a – b, is a binary operation on Z+, but it is not closed.

  31. Unary Operations A function g : A  A is called aunary operation on A. • Examples: The function h : R+  R+ defined by h(a) = 1/a is a unary operation on R+.

  32. The Pigeonhole Principle If m pigeons occupy n pigeonholes and m > n, then at least one pigeonhole has two or more pigeons roosting in it.

  33. Generalized Form If X and Y are finite sets with |X| = n, |Y| = m and k = n/m, then there are at least k values a1, a2,…, ak  X such that f(a1) = f(a2) = … f(ak). • Example: n = 5, m = 3 k = n/m = 5/3 = 2.

  34. Example 1 Any subset of size 6 from the set S = {1, 2, 3, …, 9} must contains two elements whose sum is 10. Proof. Pigeons: the elements of a 6-element subset of S. Pigeonholes: the subsets {1,9},{2,8},{3,7},{4,6},{5}. By the pigeonhole principal, there are at least two elements whose sum is 10. #

  35. Example 2 Prove that if 101 integers are selected from the set S = {1, 2, 3, …, 200}, then there are two integers such that one divides the other. Proof.The fundamental theorem of arithmetic: Every positive integer (except 1) can be represented in exactly one way apart from rearrangement as a product of one or more primes.  xS [x = 2ky], with k  0, and gcd(2,y) = 1.  yT={1,3,5,…,199}. Pigeons: 101 selected integers. Pigeonholes: 100 elements of T.   two selected integers 2my and 2ny. #

  36. Example 3 Let m  Z+ with m odd. Prove that there exists a positive integer n such that m divides 2n – 1. Proof. Pick m+1 positive integers: 21–1, 22–1, 23–1, …, 2m–1, 2m+1–1.   s, t  Z+ [(2s–1) mod m = (2t–1) mod m], 1s<tm+1. (By the pigeonhole principal and the division algorithm)  Let 2s–1 = q1m+r and 2t–1 = q2m+r.  2t–2s = (q2 – q1)m = 2s (2t-s–1)  m is odd.  m| (2t-s–1)  n = t-s. #

  37. Brainstorm 假設有一座小鎮,(1) 鎮上每個人頭髮的數目都不同﹔(2) 沒有人的頭髮數目剛好是500﹔(3) 鎮的人口比鎮裏任何一人頭髮的數目為多。 問題:鎮上最多有多少人?

More Related