Download presentation
Presentation is loading. Please wait.
1
Discrete Structures Chapter 5 Relations and Functions Nurul Amelina Nasharuddin Multimedia Department
2
2 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
Outline Cartesian products and relations Functions: Plain, one-to-one, onto Function composition and inverse functions Functions for computer science Properties of relations Computer recognition: Zero-one matrices and directed graphs Use in database example 3
4
4 Relationship
5
5 Recall: Cartesian Products 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
6
6 Properties: 1.If A, B are finite, it follows from the rule of product that |A × B| = |A||B| 2.Although we generally will not have A × B = B × A, we will have |A×B|=|B×A| Recall: Cartesian Products
7
7 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) B 3 Example (1)
8
8 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 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. Example (2)
9
9
10
10 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 Example (3)
11
11 Example (3)
12
12 Relations Let A = {0,1,2}, B = {1,2,3}. A x B = {(0,1), (0,2), (0,3), (1,1), (1,2), (1,3), (2,1), (2,2), (2,3)} Let say an element x in A is related to an element y in B iff x is less than y. x R y: x is related to y 0 R 1, 0 R 2, 0 R 3, 1 R 2, 1 R 3, 2 R 3 The set of all ordered pair in A x B where elements are related {(0,1), (0,2), (0,3), (1,2), (1,3), (2,3)}
13
13 Relations For sets A, B, a (binary) relation R from A to B is a subset of A × B. Any subset of A × A is called a (binary) relation on A Given an ordered pair (a, b) in A x B, x is related to y by R (x R y) iff (x, y) is in R In general, for finite sets A, B with |A| = m and |B|= n, there are 2 mn relations from A to B, including the empty relation as well as the relation A × B itself
14
14 Example (1) Let 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. i. ii.{(2, 4)} iii.{(2, 4), (2, 5)} iv.{(2, 4), (3, 4), (4, 4)} v.{(2, 4), (3, 4), (4, 5)} vi.A × B Since |A × B| = 6, there are 2 6 possible relations from A to Β (for there are 2 6 possible subsets of A × B )
15
15 Example (2) Let A = {1,2}, B = {1,2,3} and define a binary relation from A to be as follows: Given any (x,y) A x B, (x,y) R x – y is even a)State explicitly which ordered pairs are in A x B and which are in R b)Is 1 R 3? c)Is 2 R 3? d)Is 2 R 2?
16
16 Example (2) a)A x B= {(1,1), (1,2), (1,3), (2,1), (2,2), (2,3)} and R, when x – y is even = {(1,1), (1,3), (2,2)} A x B b)Is 1 R 3? Yes c)Is 2 R 3? No d)Is 2 R 2? Yes (1,1) R because 1 – 1= 0 is even (1,2) R because 2 – 1 = 1 is not even
17
17 Example (3) Let B={1,2} and A=P(B) = { ,{1},{2},{1,2}} |A×A| = 4.4 = 16 A×A = {( ∅, ∅ ),( ∅,{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})}
18
18 Example (4) 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
19
19 (7, 7), (7, 11) R (8, 2) R (7, 11) R or 7 R 11 (infix notation)
20
20 Arrow Diagrams of Relations Let A = {1,2,3}, B = {1,3,5} For all x A and y B, relations S and T (x,y) S x < y T = {(2,1), (2,5)}
21
21 Functions For nonempty sets A and 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 Sample functions: f : R R, f(x) = x 2 f : Z Z, f(x) = x + 1 f : Q Z, f(x) = 2
22
22 Functions A function f from a non-empty set A to a set B is a relation from A to B satisfying the following two properties: 1) x A, y B such that (x,y) f 2) (x, y), (x, y’) f, y = y’ The 1st property says every x A is related to at least one y B The 2nd property says each x A is related to at most one y B That is, a relation from A to B is a function from A to B if and only if every x A is related to exactly one y B
23
23 Example (1) Let A = {1,2,3}, B = {7,8,9} a)g = {(1,8), (2,9), (3,9), (3,10)} A x B is not a function from A to B: (3,9), (3,10) g but 9 10. Relation g fails to be a function because 3 A is related to two (distinct) elements 9, 10 B b)h = {(1,9), (2,10), (3,9)} A x B is a function from A to B. Relation h is a function because each element of A is related to exactly one element in B
24
24 Arrow Diagram 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 (inverse image) of b
25
25 Arrow Diagram The arrow diagram of a function from A to B has the characteristic that there is exactly one arrow shooting out from every element of A However, a element of B can be hit by no arrows, one arrow, or many arrows
26
26 Domain and Codomain 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 Eg: Let A = {1, 2, 3}, B = {w, x, y, z }, f={(1, w), (2, x), (3, x)} Domain of f = {1,2,3}, the codomain of f = {w, x, y, z}, and the range of f = f (A) = {w, x}
27
27 Interesting Functions in Computer Science Greatest integer function, or floor function: This function f: R → Z, is given by f(x) = x = the greatest integer n less than or equal to x, n x n + 1 Consequently, if x is a real number and n is an integer, then f(x) = x = is the integer to the immediate left of x on the real number line. For this function, we find that 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 3) 7.7 + 8.4 = 16.1 = 16 ≠ 15 = 7 + 8 = 7.7 + 8.4
28
28 Interesting Functions in Computer Science Ceiling function: This function g: R → Z, is given by g(x) = x = the least integer greater than or equal to x, n x n + 1 Consequently, if x is a real number and n is an integer, then g(x) = x = is the integer to the immediate right of x on the real number line. For this function, we find that 1) 3 = 3, 3.01 = 3.7 = 4 = 4 , –3.01 = –3.7 = –3; 2) 3.6 + 4.5 = 8.1 = 9 = 4 + 5 = 3.6 + 4.5 3) 3.3 + 4.2 = 7.5 = 8 ≠ 9 = 4 + 5 = 3.3 + 4.2
29
29 Interesting Functions in Computer Science Trunc function (for truncation): 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
30
30 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 Total Number of Functions
31
31 Total Number of Functions Let A = {1, 2, 3}, B = {w, x, y, z}, f = {(1, w), (2, x), (3, x)} There are 2 4.3 =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 Therefore, there are 4 3 = |B| |A| = 64 functions from A to B, and 3 4 = |A| |B| = 81 functions from B to A
32
32 Properties of Functions Two important properties that functions may satisfy: a)The property of being one-to-one and b)The property of being onto Functions that satisfy both properties are called one- to-one correspondences or one-to-one onto functions
33
33 Let f be a function from A to B. f is called one-to- one, or injective, iff for all elements x 1 and x 2 in A If f(x 1 ) = f(x 2 ), then x 1 = x 2 or, equivalently if x 1 x 2, then f(x 1 ) f(x 2 ) Each element of B appears at most once as the image of an element of A One-to-one Function
34
34 One-to-one Function
35
35 Not One-to-one Function
36
36 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 One-to-one Function
37
37 Let X = {1,2,3} and Y = {a,b,c,d} Define H: X Y as follows: H(1) = c, H(2) = a, H(3) = d. Is H one-to-one? Define K: X Y as follows: K(1) = d, K(2) = b, K(3) = d. Is K one-to-one? Identifying One-to-one Functions Defined on Finite Sets
38
38 Suppose f is a function defined on an infinite set X. By definition, f is one-to-one iff the following is true: x 1, x 2 X, if f(x 1 ) = f(x 2 ), then x 1 = x 2 (1)Suppose x 1 and x 2 are elements of X such that f(x 1 ) = f(x 2 ) (2) Show that x 1 = x 2 Identifying One-to-one Functions Defined on Infinite Sets
39
39 Consider the function f: R→ R where f (x) = 3x + 7 for all x R Then for all x 1, x 2, R, we find that f (x 1 ) = f (x 2 ) 3x 1 + 7 = 3x 2 + 7 3x 1 = 3x 2 (minus both side with 7) x 1 = x 2, (dividing both side with 3) so the given function f is one-to-one Example (1)
40
40 On the other hand, suppose that g: R → R is the function defined by g (x) = x 4 – x for each real number x Let x 1 = 0 and x 2 =1.Then g(x 1 ) = g(0) = (0) 4 – 0 = 0 g(x 2 ) = g(1) = (1) 4 – (1) = 1 – 1 = 0 Hence g(x 1 ) = g(x 2 ) but x 1 x 2 (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 ) but x 1 x 2 Example (2)
41
41 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 Example (3)
42
42 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|) Calculate Total No of One-to-one Functions
43
43 Consequently, for A, B where A = {1, 2, 3} and B = {1, 2, 3, 4, 5}, there are P(5,3)= P(|B|,|A|) =5. 4. 3 = 60 one-to-one functions f: A → B. Example (1)
44
44 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 Onto Function
45
45 Not Onto Function
46
46 Identifying Onto Functions Defined on Finite Sets Let X = {1,2,3,4} and Y = {a,b,c} Define H: X Y as follows: H(1) = c, H(2) = a, H(3) = c, H(4) = b. Is H onto? Define K: X Y as follows: K(1) = c, K(2) = b, K(3) = b, K(4) = c. Is K onto?
47
47 Suppose f is a function from a set X to a set Y, and suppose Y is infinite. By definition, f is onto iff the following is true: y Y, x X such that f(x) = y (1)Suppose that y is any element of Y (2) Show that there is an element of X with f(x) = y Identifying Onto Functions Defined on Infinite Sets
48
48 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 Example (1)
49
49 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 Example (2)
50
50 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 Example (3)
51
51 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 Example (4)
52
52 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 (no z!) 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| Example (5)
53
53 If f: A → B, then f is said to be bijective, or to be a one-to-one correspondences, if f is both one-to-one and onto. Eg: 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? Ans: f is one-to-one (every element of B appear at most once), and f is onto (f(A) = B) One-to-one Correspondences
54
54 Let A = {1, 2, 3, 4} and B = {w, x, y, z}, and g = {(w, 1), (x, 2), (y, 3), (z, 4)}. Is g a one-to-one correspondence from B (on) to A? Example (1)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.