Presentation is loading. Please wait.

Presentation is loading. Please wait.

11 DISCRETE STRUCTURES DISCRETE STRUCTURES UNIT 5 SSK3003 DR. ALI MAMAT 1.

Similar presentations


Presentation on theme: "11 DISCRETE STRUCTURES DISCRETE STRUCTURES UNIT 5 SSK3003 DR. ALI MAMAT 1."— Presentation transcript:

1 11 DISCRETE STRUCTURES DISCRETE STRUCTURES UNIT 5 SSK3003 DR. ALI MAMAT 1

2 22 Relations and Functions Objectives : On completion of this chapter, student should be able to: 1. Define a relation and function 2. Determine the type of function (one-to-one, onto, one-to-one correspondence) 3. Find a composite function 4. Find an inverse function

3 33 Contents 1. Cartesian product and relations 2. Functions: Plain and One-to-One 3. Onto Functions 4. Function Composition and inverse functions

4 4 Relationship Set Cartesian Product Relation Function

5 55 RELATIONS AND FUNCTIONS CARTESIAN PRODUCTS AND RELATIONS Definition 5.1 For sets A, B, the Cartesian product, or cross product, of A and B is denoted by A × B and equals {(a, b) | a ∈ A, b ∈ B}. Elements of A × B are ordered pairs. For (a, b), (c, d) ∈ A × B, (a, b) = (c, d) if and only if a = c and b = d. 5 RELATIONS AND FUNCTIONS

6 666 If A, B are finite, it follows from the rule of product that |A × B| = |A||B|. Although we generally will not have A × B = B × A, we will have |A×B|=|B×A| Although A, B ⊆ U, it is not necessary that A × B ⊆ U. If (a 1, a 2, …, a n ), (b 1, b 2,...,b n ) ∈ A 1 × A 2 × … × A n, then (a1, a2, …., an) = (b1, b2, …, bn) if and only if ai = bi, ∀ 1 ≤ i ≤ n.

7 77 Example 5.1 Let A = {2, 3, 4}, B = {4, 5}. Then a) A × B = {(2, 4), (2, 5), (3, 4), (3, 5), (4, 4), (4, 5)}. b) B × A = {(4, 2), (4, 3), (4, 4), (5, 2), (5, 3), (5, 4)}. c) B 2 = B × B = {(4, 4), (4, 5), (5, 4), (5, 5)}. d) B 3 = B × B × B = {(a, b, c) | a, b, c ∈ B}; for instance, (4, 5, 5) ∈ B3. 7

8 88 Example 5.3 An experiment E is conducted as follows: A single dice is rolled and its outcome noted, and then a coin is flipped and its outcome noted. Determine a sample space S for E. 8

9 99 S1={1, 2, 3, 4, 5, 6} be a sample space dice. S2= {H, T} be a sample space coin. Then S = S1 × S2 is a sample space for E. This sample space can be represented pictorically with a tree diagram that exhibits all the possible outcomes of experiment E.

10 10

11 11 Example 5.4 At the Wimbledon Tennis Championships, women play at most three sets in a match. The winner is the first to win two sets. If we let N and E denote the two players, the tree diagram indicates the six ways in which this match can be won. For example, the starred line segment (edge) indicates that player E won the first set. The double starred edge indicates that player N has won the match by winning the first and third sets. 11

12 12

13 13 Definition 5.2 (relation) For sets A, B, any subset of A × B is called a (binary) relation from A to B. Any subset of A × A is called a (binary) relation on A. 13

14 14 Example 5.5 From Example 5.1 A = {2, 3, 4}, B = {4, 5}. Then A × B = {(2, 4), (2, 5), (3, 4), (3, 5), (4, 4), (4, 5)}. The following are some of the relations from A to B. a) ∅ b) {(2, 4)} c) {(2, 4), (2, 5)} d) {(2, 4), (3, 4), (4, 4)} e) {(2, 4), (3, 4), (4, 5)} f) A × B Since |A × B| = 6, it follows from Definition 5.2 that there are 2 6 possible relations from A to Β (for there are 2 6 possible subsets of A × B ). 14

15 15 Example 5.6 For B={1,2}, let A=P(B)= { ∅,{1},{2},{1,2}}. |A×B| = 4.4 = 16. A×B = {( ∅, ∅ ),( ∅,{1}),( ∅,{2}),( ∅,{1,2}), ({1}, ∅ ), ({1},{1}), ({1},{2}), ({1},{1,2}) ({2}, ∅ ),({2},{1}), ({2},{2}), ({2},{1,2}) ({1,2}, ∅ ),({1,2},{1}),({1,2},{2}, ({1,2},{1,2})} The following is an example of a relation on A: R = {( ∅, ∅ ), ( ∅, {1}), ( ∅, {2}), ( ∅, {1, 2}), ({1}, {1}), ({1}, {1, 2}), ({2}, {2}), ({2}, {1, 2}), ({1, 2}, {1, 2})}. 15

16 16 Example 5.7 With A = Z + (set of positive integers), we may define a relation R on set A as {(x, y) | x ≤ y}. This is the familiar “is less than or equal to” relation for the set of positive integers. It can be represented graphically as the set of points, with positive integer components, located on or above the line y = x in the Euclidean plane, as partially shown in the figure below. 16

17 17 (7, 7), (7, 11) ∈ R (8, 2) ∉ R (7, 11) ∈ R or 7 R 11 (infix notation)

18 18 Question ?????

19 19 FUNCTIONS: ONE-TO-ONE Definition 5.3 For nonempty sets A, B, a function, or mapping, f from A to B, denoted f: A → B, is a relation from A to B in which every element of A appears exactly once as the first component of an ordered pair in the relation. 19

20 20 Function

21 21 We often write f(a) = b when (a, b) is an ordered pair in the function f. For (a, b) ∈ f, b is called the image of a under f, whereas a is a preimage of b. The definition suggests that f is a method for associating with each a ∈ A the unique element f (a) = b ∈ B. Consequently, (a, b), (a, c) ∈ f implies b = c.

22 22 Example 5.9 For A = {1, 2, 3} and B = {w, x, y, z}, f = {(1, w), (2, x), (3, x)} is a function, and consequently a relation, from A to B. R 1 = {(1, w), (2, x)} and R 2 = {(1, w), (2, w), (2, x), (3, z)} are relations, but not functions, from A to B. (Why?) 22

23 23 Definition 5.4 For the function f: A → B, A is called the domain of f and B the codomain of f. The subset of B consisting of those elements that appear as second components in the ordered pairs of f is called the range of f and is also denoted by f (A) because it is the set of images (of the elements of A) under f. In Example 5.9, f = {(1, w), (2, x), (3, x)} the domain of f = {1,2,3}, the codomain of f = {w, x, y, z}, and the range of f = f (A) = {w, x}. 23

24 24 a may be regarded as an input that is transformed by f into the corresponding output, f(a).

25 25 Example 5.10 Many interesting functions arise in computer science. a) A common function encountered is the greatest integer function, or floor function. This function f: R → Z, is given by f (x) = x = the greatest integer less than or equal to x. Consequently, f (x) = x, if x ∈ Z; and, when x ∈ R – Z, f (x) is the integer to the immediate left of x on the real number line. For this function, we find that 25 

26 26 1) 3.8 = 3, 3 = 3, –3.8 = –4, –3 = –3; 2) 7.1 + 8.2 = 15.3 = 15 = 7 + 8 = 7.1 + 8.2; and 3) 7.7 + 8.4 = 16.1 = 16 ≠ 15 = 7 + 8 = 7.7 + 8.4. 26

27 27 b) A second function –one related to the floor function in part (a) –is the ceiling function. The function g: R → Z is defined by g(x) = x = the least integer greater than or equal to x. So g (x) = x when x ∈ Z, but when x ∈ R – Z, then g (x) is the integer to the immediate right of x on the real number line. 27

28 28 In dealing with the ceiling function, we find that 1) 3 = 3, 3.01 = 3.7 = 4 = 4, –3 = –3,–3.01 = –3.7 = –3; 2) 3.6 + 4.5 = 8.1 = 9 = 4 + 5 = 3.6 + 4.5; and 3) 3.3 + 4.2 = 7.5 = 8 ≠ 9 = 4 + 5 = 3.3 + 4.2. 28

29 29 c) The function trunc (for truncation) is another integer – valued function defined on R. This function deletes the fractional part of a real number. For example, trunc (3.78) = 3, trunc (5) = 5, trunc (–7.22) = –7. Note that trunc (3.78) = 3.78 = 3 while trunc (–3.78) = –3.78 = –3. 29

30 30 No. of Functions In Example 5.9 ( For A = {1, 2, 3} and B = {w, x, y, z}, f = {(1, w), (2, x), (3, x)} ) there are 2 12 = 4096 relations from A to B. We have examined one function among these relations, and now we wish to count the total number of functions from A to B.

31 31 For general case, let A, B be nonempty sets with |A| = m, |B| = n. Consequently, If A = {a 1, a 2, …, a m } and B={b 1,b 2,…,b n }, then a typical function f: A → B can be described by {(a 1, x 1 ), (a 2, x 2 ), (a 3, x 3 ), …, (a m, x m )} – m ordered pairs. x 1 can selected from any of the n elements of B x 2 “ ………………….. x m “ In this way, using the rule of product, there are n m = |B| |A| functions from A to B. 31

32 32 Therefore, for A, B in Example 5.9, there are 4 3 = |B| |A| =64 functions from A to B, and 3 4 = |A| |B| = 81 functions from B to A. Unlike the situation for relations, we cannot always obtain a function from B to A by simply interchanging the components in the ordered pairs of a function from A to B (or vice versa). Try to interchange the components in the f! For A = {1, 2, 3} and B = {w, x, y, z}, f = {(1, w), (2, x), (3, x)} ) 32

33 33 Definition 5.5 A function f: A → B is called one-to-one, or injective, if each element of B appears at most once as the image of an element of A. 33

34 34

35 35

36 36 One-to-one Function If f: A → B is one-to-one, with A, B finite, we must have |A|≤|B|. For arbitrary sets A, B, f: A → B is one-to-one if and only if for all, a 1, a 2 ∈ A, f (a 1 ) = f (a 2 ) ⇒ a 1 = a 2.

37 37 Example 5.13 Consider the function f: R→ R where f (x) = 3x + 7 for all x ∈ R. Then for all x, x, ∈ R, we find that f (x1) = f (x2) ⇒ 3x 1 + 7 = 3x 2 + 7 ⇒ 3x 1 = 3x 2 ⇒ x 1 = x 2, so the given function f is one-to-one. 37

38 38 One-to-one function On the other hand, suppose that g: R → R is the function defined by g (x) = x 4 – x for each real number x. Then g(0) = (0) 4 – 0 = 0 and g(1) = (1)4 – (1) = 1 – 1 = 0. Consequently, g is not one-to-one, since g(0) = g (1) but 0 ≠ 1 – that is, g is not one to-one because there exist real numbers x 1, x 2 where g (x 1 ) = g (x 2 ) ⇒ x 1 = x 2.

39 39 Example 5.14 Let A = {1, 2, 3} and B = {1, 2, 3, 4, 5}. The function f = {(1, 1), (2, 3), (3, 4)} is a one-to-one function from A to B; g = {(1, 1), (2, 3), (3, 3)} is a function from A to B, but fails to be one-to-one because g(2) = g(3) = 3 but 2 ≠ 3. For A, B in the above example there are 2 15 relations from A to B and 5 3 of these are functions from A to B. The next question we want to answer is how many functions f: A → B are one-to-one. 39

40 40 With A = {a 1, a 2, a 3, …, a m }, B = {b 1, b 2, b 3, …, b n }, and m ≤ n, a one-to-one function f: A → B has the form {(a 1, x 1 ), (a 2, x 2 ), (a 3, x 3 ), …, (a m, x m )}, where there are n choices for x 1 n – 1 choices for x 2 n - 2 choices for x 3 ……….. n–m+1 choices for x m., the number of one-to-one functions from A to B is n(n-1)(n-2)…(n-m+1)=n!/(n-m)! = P(n,m)= P(|B|,|A|) 40

41 41 No. of One-to-One Functions Consequently, for A, B in Example 5.14 (A = {1, 2, 3} and B = {1, 2, 3, 4, 5}), there are P(5,3) = 5. 4. 3 = 60 one-to-one functions f: A → B.

42 42 Question ?????

43 43 Onto Functions: Definition 5.9 A function f: A→ B is called onto, or surjective, if f (A)=B – that is, if for all b ∈ B there is at least one a ∈ A with f (a) = b. 43

44 44 Onto function

45 45

46 46 Example 5.19 The function f: R → R defined by f(x) = x 3 is an onto function. if r is any real number in the codomain of f, then the real number 3√r is in the domain of f and f ( 3 √r) = ( 3 √r) 3 = r. e.g. f(3) = 27, f(-3) = -27 Hence the codomain of f=R=range of f, and the function f is onto.

47 47 The function g: R → R, where g (x) = x 2 for each real number x, is not an onto function. In this case, no negative real number appears in the range of g. For example, for –9 to be in the range of g, we would have to be able to find a real number r with g(r) = r 2 = –9. Note, however, that the function h: R → [ 0, +∞ ) defined by h(x) = x 2 is an onto function. 47

48 48 Example 5.20 Consider the function f: Z → Z, where f(x) = 3x + 1 for each x ∈ Z. Here the range of f = {…, –8, –5, –2, 1, 4, 7, …} ⊂ Z, so f is not an onto function. E.g. f(x) = 3x + 1 = 8 then x = 7/3. Rational number 7/3 is not an integer –so there is no x in the domain Z with f(x) = 8. 48

49 49 On the other hand, each of the functions 1) g: Q → Q, where g(x) = 3x + 1 for x ∈ Q; and 2) h: R → R, where h(x) = 3x + 1 for x ∈ R is an onto function. (Q is a set of rational numbers: a/b) Furthermore, 3x 1 + 1 = 3x 2 + 1 ⇒ 3x 1 = 3x 2 ⇒ x 1 = x 2, regardless of whether x 1 and x 2 are integers, rational numbers, or real numbers. Consequently, all three of the functions f, g and h are one-to-one. 49

50 50 Example 5.21 If A = {1, 2, 3, 4} and B = {x, y, z}, then f 1 = {(1, z), (2, y), (3, x), (4, y)} and f 2 = {(1, x), (2, x), (3, y), (4, z)} are both functions from A onto B. However, the function g = {(1, x), (2, x), (3, y), (4,y)} is not onto, because g (A) = {x, y} ⊂ B. If A, B are finite sets, then for an onto function f: A → B to possibly exist we must have |A|≥ |B|where |A|=m≥ n= |B|. ******* 50

51 51 Function Composition and Inverse Functions Objective (Continue) 1. Define a relation and function 2. Determine the type of function (one-to-one, onto) 3. Find a composite function 4. Find an inverse function 51

52 52 Contents 1. One-to-one correspondence function 2. Function equality 3. Composite function 4. Characteristics of composite function 5. Converse of relation 6. Inverse function

53 53 One-to-one correspondence function Definition 5.15 If f: A → B, then f is said to be bijective, or to be a one-to- one correspondence, if f is both one-to-one and onto. Example 5.50 If A = {1, 2, 3, 4} and B = {w, x, y, z}, then f = {(1,w),(2,x),(3,y),(4, z)} is a one-to-one correspondence from A (on) to B, Why? f is one-to-one (every element of B appear at most once), and f is onto (f(A) = B) 53

54 54 and g = {(w, 1), (x, 2), (y, 3), (z, 4)} is a one-to-one correspondence from B (on) to A. g is one-to-one and g is onto.

55 55 Definition 5.16 The function 1 A : A → A, defined by 1 A (a) = a for all a ∈ A, is called the identity function for A. It is a function that always returns the same value that was used as its argument. In terms of equations, the function is given by f(x) = x.functionequations 55

56 56 Function equality When are f and g equal? Definition 5.17 If f, g: A → B, we say that f and g are equal and write f= g, if f (a) = g (a) for all a ∈ A. But sometimes f ≠ g even though f (a) = g (a), ∀ a ∈ A. This occurs when f, g are functions with a common domain A.

57 57 Example 5.51 Let f: Z → Z, g: Z → Q where f(x) = x = g(x), for all x ∈ Z. Then f, g share the common domain Z, have the same range Z, and act the same on every element of Z. Yet f ≠ g! Here f is a one-to-one correspondence, whereas g is one-to-one but not onto (f(A) ≠ B) ; so the codomains do make a difference. 57

58 58

59 59 Composite Function Function composition is an operation for combining two functions. Definition 5.18 If f: A → B and g: B → C, we define the composite function, which is denoted g o f: A → C, by (g o f ) (a) = g (f (a)), for each a ∈ A. (i.e. element a of g is replaced by f(a)) 59

60 60 Example 5.53 Let A = {1, 2, 3, 4}, B = {a, b, c}, and C = {w, x, y, z} with f: A → B and g: B → C given by f = {(1, a), (2, a), (3, b), (4, c)} and g = {(a, x), (b, y), (c, z)}. For each element of A we find: (g o f) (1) = g (f (1))= g (a) = x (g o f) (2) = g (f (2))= g (a) = x (g o f) (3) = g (f (3))= g (b) = y (g o f) (4) = g (f (4))= g (c) = z So g o f = {(1, x), (2, x), (3, y), (4, z)}. Note: The composition f o g is not defined (domain of f is A and codomain of g is C). 60 Function f 1 ------ a 2 ------ a 3 ------ b 4 ------ c

61 61 Example 5.54 Let f: R → R, g: R → R be defined by f (x) = x 2, g(x) = x + 5. Then (g o f) (x) = g (f (x)) = g (x 2 ) = x 2 + 5, whereas (f o g) (x) = f (g (x)) = f (x+ 5) = (x+ 5) 2 = x 2 + 10x + 25. Here g o f: R → R and f o g: R → R, but (g o f) (1) = 6 ≠ 36 = (f o g) (1), so even though both composites fog and gof can be formed, we do not have f o g = g o f. 61

62 62 Consequently, the composition of functions is not, in general, a commutative operation. The definition and examples for composite functions required that the codomain of f = domain of g. If range of f ⊆ domain of g, this will actually be enough to yield the composite function g o f: A → C. Also, for any f: A → B, we observed that f o 1 A = f = 1 B o f. 62

63 63 Theorem 5.5 Let f: A → B and g: B → C. a) If f, g are one-to-one, then g o f is one-to-one. b) If f, g are onto, then g o f is onto. Proof: a)To prove that g o f: A → C is one-to-one, let a 1, a 2 ∈ A with (g o f )(a1) = (g o f) (a 2 ). Then (g o f)(a 1 )=(g o f)(a 2 ) ⇒ g(f (a 1 )) = g( f (a 2 )) ⇒ f(a1) = f(a 2 ), because g is one-to-one. Also, f (a 1 ) = f (a 2 ) ⇒ a 1 = a 2, because f is oneto-one. Consequently, g o f is one-to-one. 63

64 64 b) For g o f: A → C, let z ∈ C. Since g is onto, there exists y ∈ B with g (y) = z. With f onto and y ∈ B, there exists x ∈ A with f (x) = y. Hence z = g (y) = g ( f (x)) = (g o f ) (x), so the range of g o f = C = the codomain of g o f, and g o f is onto. 64 x f(x)=yg(y)=z A BC f g

65 65

66 66

67 67 Theorem 5.6 (associative property) If f: A → B, g: B → C, and h: C → D, then (h o g) o f = h o (g o f ). Proof: Since the two functions have the same domain, A, and codomain, D, the result will follow by showing that for every x ∈ A, ((h o g) o f)(x) = (h o (g o f ))(x). (See the diagram shown in Fig 5.9). 67

68 68 Using the definition of the composite function, we find that ((h o g) o f) (x) = (h o g) (f (x)) = h ( g (f (x))), whereas (h o (g o f )) (x) = h ((g o f ) (x)) = h (g (f (x))). Since ((h o g) o f ) (x) = h (g ( f (x))) = (h o ( g o f )) (x), for each x in A, it now follows that (h o g) o f = h o (g o f). Consequently, the composition of functions is an associative operation. 68

69 69

70 70 Definition 5.19 (recursive definition) If f: A → A we define f 1 = f, and for n ∈ Z+, f n+1 = f o (f n ). This definition is another example wherein the result is defined recursively. With f n+1 = f o (f n ), we see the dependence of f n+1 on a previous power, namely, f n. 70

71 71 Example 5.56 With A = {1, 2, 3, 4} and f: A → A defined by f = {(1, 2), (2, 2), (3, 1), (4, 3)}, we have f o f(1) = f(f(1) = f(2) = 2 f o f(2) = f(f(2)) = f(2) = 2 f o f(3) = f(f(3)) = f(1) = 2 f o f(4) = f(f(4)) = f(3) = 1 f 2 = f o f = {(1, 2), (2, 2), (3, 2), (4, 1)} and f 3 = f o f 2 = f o f o f = {(1, 2), (2, 2), (3, 2), (4, 2)}. (What are f 4, f 5 ?) 71 function f 1 ---------- 2 2 ----------2 3 --------- 1

72 72 Converse of relation Definition 5.20 For sets A, B, if R is a relation from A to B, then the converse of R, denoted R c, is the relation from B to A defined by R = {(b, a)|(a, b) ∈ R}. So if A = {1, 2, 3, 4}, B = {w, x, y}, and R = {(1, w), (2, w), (3, x)}, then R c = {(w, 1), (w, 2), (x, 3)}, a relation from B to A. 72

73 73 Since a function is a relation we can also form the converse of a function. For the same preceding sets A, B, let f: A → B where f = {(1, w), (2, x), (3, y), (4, x)}. Then f c = {(w, 1), (x, 2), (y, 3), (x, 4)}, a relation, but not a function, from B to A. We wish to investigate when the converse of a function yields a function. 73

74 74 Example 5.57 For A = {1, 2, 3} and B = {w, x, y}, let f: A → B be given by f = {(1, w), (2, x), (3, y)}. Then f c = {(w, 1), (x, 2), (y, 3)} is a function from B to A, and we observe that f c o f = 1 A and f o f c = 1 B. Definition 5.21 If f: A → B, then f is said to be invertible if there is a function g: B → A such that g o f= 1 A and f o g = 1 B. Note that the function g in Definition 5.21 is also invertible. 74

75 75 Example 5.58 Let f, g: R → R be defined by f (x) = 2x + 5, g (x) = (1/2)(x – 5). Then (g o f) (x) = g( f (x)) = g (2x + 5) = (1/2)[(2x + 5) – 5] = x, and (f o g )(x) = f(g (x)) = f((1/2)(x –5)) =2[(1/2)(x– 5)] + 5 = x, so f o g = 1 R and g o f = 1 R. Consequently, f and g are both invertible functions. 75

76 76 Inverse Function Theorem 5.7 If a function f: A → B is invertible and a function g: B→A satisfies g o f = 1 A and f o g = 1 B, then this function g is unique. We shall call the function g the inverse of f and shall adopt the notation g = f –1. Theorem 5.7 also implies that f –1 = f c. Whenever f is an invertible function, so is the function f -1, and (f –1 ) –1 = f. 76

77 77 Theorem 5.8 A function f: A → B is invertible if and only if it is one-to- one and onto. Example 5.59 From Theorem 5.8 it follows that the function f 1 : R → R defined by f 1 (x) = x 2 is not invertible (it is neither one-to-one nor onto), but f 2 : [0, +∞) → [0, +∞) defined by f 2 (x) = x 2 is invertible with f 2 –1 (x) = √ x. 77

78 78 Theorem 5.9 If f: A → B, g: B → C are invertible functions, then g o f: A → C is invertible and (g o f ) –1 = f –1 o g –1. Example Let f:R→ R defined by f(x)=3x+5 f(x) = y, hence f -1 (y) = x 78 x y=f(x) f f -1

79 79 f(x) = y = 3x + 5 x = (y- 5)/3 f -1 (y) = x, hence f -1 (y) = (y-5)/3 Rename y by x, f -1 (x) = (x-5)/3

80 80 Exercise f: R → R is defined by f(x) = 4x – 1. Find its inverse function.

81 81

82 82 END THANK YOU


Download ppt "11 DISCRETE STRUCTURES DISCRETE STRUCTURES UNIT 5 SSK3003 DR. ALI MAMAT 1."

Similar presentations


Ads by Google