Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 5 Relations and Functions.

Similar presentations


Presentation on theme: "1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 5 Relations and Functions."— Presentation transcript:

1 1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 5 Relations and Functions

2 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 2 mn relations from A to B, including the empty relation and the relation A  B itself.

3 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 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 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 6 Relation Matrices Let X, Y be sets and R a relation from X to Y  Write the matrix M = (m ij ) of the relation as follows: Rows of M = elements of X Columns of M = elements of Y Element m i,j = 0 if the element of X in row i and the element of Y in column j are not related Element m i,j = 1 if the element of X in row i and the element of Y in column j are related

7 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 8 Matrices  Let E = (e ij ) m  n, F = (f ij ) m  n be two m  n (0,1)- matrices. We say E  F if e ij  f ij for all i,j.  For n  Z +, (0,1)-matrix I n = (  ij ) n  n where  ij = 1 if i = j, otherwise  ij = 0.  Let A = (a ij ) m  n be a (0,1)-matrix. The transpose of A, denoted by A tr, is the matrix (a* ji ) n  m where a* ji = a ij for all i,j.

9 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 reflexive iff I n  M; (All terms m ii in the main diagonal of M are 1.) (b) R is symmetric iff M = M tr. (a ij = a ji for all i and j.) (c) R is transitive iff M 2  M. (c ij in M 2 is nonzero then entry m ij in M is also nonzero.) (d) R is antisymmetric iff M  M tr  I n.

10 10 M =M2=M2= M 2 32  0  m 31 m 12 +m 32 m 22 +m 33 m 32 +m 34 m 42  0  There exists k such that m 3k m k2  0  m 3k  0 and m k2  0  m 32  0. # Property (c)

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

12 12 Topological Sorting a b c d e abcde 

13 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 14 Equivalence Relations Let X be a set and R a relation on X. R is an equivalence relation on X if R is reflexive, symmetric and transitive. (e.g. “=”)

15 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 16 Proof of Theorem 7.6 (a) By the reflexive property of R. (b) (  ) 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 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 18 Partitions A partition S on a set X is a family {A 1, A 2,…, A n } of subsets of X, such that A 1 ∪ A 2 ∪ A 3 ∪ … ∪ A n = X A j ∩A k =  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 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 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 21 How many functions? Let X,Y be nonempty sets with |X| = m and |Y| = n. Define the functions with domain X. x2x2 x1x1 xmxm y2y2 y1y1 ynyn For each x i we select one of the n elements of Y.  There are n m functions from X to Y.

22 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 x 1, x 2  X there exist two distinct elements y 1, y 2  Y such that f(x 1 ) = y 1 and f(x 2 ) = y 2. 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) = x 2 is not one- to-one, since for every real number x, f(x) = f(-x).

23 23 How many one-to-one functions? Let X,Y be nonempty sets with |X| = m and |Y| = n, where m  n. x2x2 x1x1 xmxm y2y2 y1y1 ynyn There are n choices for x 1, n-1 choices for x 2, n-2 choices for x 3, and so on.  There are P(n,m) one-to-one functions from X to Y.

24 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) = x 3 is an onto function. The function g: R  R defined by g(x) = x 2 is not an onto function.

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

26 26 How many onto functions? Let X,Y be nonempty sets with |X| = m and |Y| = n.  There are C(n,n)n m – C(n,n-1)(n-1) m + C(n,n-2)(n-2) m – … + (-1) n-1 C(n,1) 1 m = 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 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) = x 3 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 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) = x 2, then f -1 (4) = ± 4 1/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 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) = x 2 -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 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 31 Unary Operations A function g : A  A is called a unary operation on A.  Examples: The function h : R +  R + defined by h(a) = 1/a is a unary operation on R +.

32 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 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 a 1, a 2,…, a k  X such that f(a 1 ) = f(a 2 ) = … f(a k ).  Example: n = 5, m = 3 k =  n/m  =  5/3  = 2.

34 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 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 = 2 k y], 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 2 m y and 2 n y. #

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

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


Download ppt "1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 5 Relations and Functions."

Similar presentations


Ads by Google