CmSc 180 – Discrete mathematics Homework 07 Solutions 1. Give an example of a function that is one-to-one but not onto Let A = {1,2}, B = {a, b, c} f: A B f = {(1,a), (2,b)} 2. Give an example of a function that is onto but not one-to-one. Let A = {1,2,3}, B = {a, b} f: A B f = {(1,a), (2,b), (3,b)} 3. Give an example of a function that is neither one-to-one nor onto Let A = {1,2,3}, B = {a, b, c} f: A B f = {(1,a), (2,b), (3,b)} 4. Give an example of a function that is both one-to-one and onto Let A = {1,2,3}, B = {a, b, c} f: A B f = {(1,a), (2,b), (3,c)} 5. How many functions are there from A = {1,2} to B = {a, b}? Write them as sets of ordered pairs. Which are one-to-one? Which are onto? Each function is a subset of the Cartesian product A x B. Therefore all functions are elements of the power set of A x B A x B = {(1,a), (1,b), (2, a), (2, b)} P(A x B) = { , {(1,a)}, {(1,b)}, {(2, a)}, {(2, b)}, {(1,a), (1,b)}, {(1,a), (2, a)}, {(1,a), (2, b)}, {(1,b), (2, a)}, {(1,b), (2, b)}, {(2,a), (2, b)}, {(1,a), (1,b), (2, a)}, {(1,a), (1,b), (2, b)}, not a function not a function not a function not a function not a function not a function function function, one-to-one, onto function, one-to-one, onto function not a function not a function not a function 1 {(1,a), (2,a), (2, b)}, not a function {(1,b), (2,a), (2, b)}, not a function {(1,a), (1,b), (2, a), (2, b)} } not a function 6. Let X = {1, 2, 3, 4}, Y = {a, b, c, d}. For each of the following subsets of X x Y determine whether it is a function or not. If it is a function, determine whether it is one-to-one, onto, or both. If it is a bijection, determine its inverse function as a set of ordered pairs. A1 = {(1,a), (2,a), (3,c), (4, b)} A2 = {(1, c), (2, a), (3, b), (4, c), (2, d)} A3 = {(1, c), (2, d), (3, a), (4, b)} A4 = {(1, d), (2, d), (4, a)} A5 = {(1, b), (2, b), (3, b), (4, b)} Record the solution in the table below; check the boxes “function”, “1 – 1”, and “onto” if the set has the corresponding properties. Write the inverse in the last column, if the function is a bijection (i.e. both 1 – 1 and onto) A1 = {(1,a), (2,a), function X 1-1 onto Inverse (if present) X X X A3-1 = { (a, 3), (b, 4), (c, 1), (d, 2) } (3,c), (4, b)} A2 = {(1, c), (2, a), (3, b), (4, c), (2, d)} A3 = {(1, c), (2, d), (3, a), (4, b)} A4 = {(1, d), (2, d), (4, a)} A5 = {(1, b), (2, b), X (3, b), (4, b)} 7. Do the following sets define functions? If so, give their domain and range: F1 = {(1, (2,3)), (2, (3,4)), (3, (1,4)), (4, (2,4))} Function, Domain : {1, 2, 3, 4}, Range: {(2,3), (3,4), (1,4), (2,4)} 2 F2 = {((1,2), 3), ((1,3), 4), ((1,3), 2)} not a function F3 = {(1, (2,3)), (2, (2,3)), (1, (2,4))} not a function F4 = {(1, (3,3)), (2, (3,3)), (3, (2,3))} Function, Domain : {1, 2, 3}, Range: { (2, 3), (3,3)} 8. Let N be the set of all non-negative integers. Determine which of the following functions are one-to-one, which are onto, and which are one-to-one and onto: a. f: N N f(n) = n2 + 2 one-to-one, not onto b. f: N N f(n) = n(mod 5) not one-to-one, not onto c. f: N N f(n) = 1 if n is odd, 0 if n is even , not one-to-one, not onto d. f: N {0, 1} f(n) = 1 if n is odd, 0 if n is even, not one-to-one, onto 9. Let X and Y be finite sets. Find a necessary condition for the existence of one-toone mappings from X to Y. The number of elements in Y must be greater or equal to the number of elements in X 10. Show that there exists a one-to-one function from A x B to B x A. Is it also onto? A x B = {(a, b) | a A bB} B x A = {(b, a) | a A bB} Define f: A x B B x A = {((a,b),(b,a)) | (a,b) A x B , (b,a) B x A} It is one-to-one and onto. One-to-one: Let (a,b) (c,d) then (b, a) (d, c) (1) By our definition of f: f((a,b)) = (b,a), f((c,d)) = (d,c) from (1): f((a,b)) f((c,d)) onto: show that y B x A x A x B such that f(x) = y Let y = (y1, y2) B x A. (1) From (1) and by def of Cartesian product B x A: y1 B, y2 A (2) From (2) and by def of Cartesian product A x B : (y2,y1) A x B (3) From (3) and by def. of f: f((y2,y1)) = (y1,y2). The choice of y = (y1,y2) was arbitrary. 3 Thus y = (y1,y2) B x A x = (y2,y1) A x B such that f(x) = y Therefore any element in B x A is an image of some element in A x B. The next problems refer to composition of functions. By definition f g = g(f(x)) 11. Let g = {(1, a), (2, b), (3, a)} be a function from X = {1, 2, 3} to Y = {a, b, c, d}, and f = {(a, w), (b, x), (c, z), (d, y)} be a function from Y to Z = {w, x, y, z}. Write g f as a set of ordered pairs. g f = f(g(x)) = {(1,w), (2, x), (3,w)} 12. Let f and g be functions from N to N defined by the equations: f(n) = 2n, g(n) = n +1 Find the compositions f f , g g, g f , and f g f f = f(f(n)) = 2(2n) = 4n g g = g(g(n)) = (n + 1) + 1 = n + 2 g f = f (g(n)) = 2(n + 1) = 2n + 2 f g = g(f(n)) = (2n) + 1 = 2n + 1 13. Let f and g be functions from N to N defined by the equations: f(n) = n2 , g(n) = 2n Find the compositions f f , g g, g f , and f g f f = f(f(n)) = (n2 ) 2 = n4 g g = g(g(n)) = 2^( 2n ) (the symbol ^ denotes the operation “raising to power” g f = f (g(n)) = (2n )2 = 22n f g = g(f(n)) = 2^( n2 ) = 2 n*n 14. Represent each function below as a composition of the functions g(x) = x + 2 h(x) = sin(x) k(x) = 2x m(x) = cos(x) n(x) = log(x) p(x) = x 3 4 a. f(x) = log 2 (x + 2) f(x) = log 2 (x + 2) = n g = n(g(x)) b. f(x) = sin(2x) = h k = h(k(x)) c. f(x) = (2 + sin (x) ) 3 = p g h = p(g(h(x)) d. f(x) = 2sin(x) = k h = k(h(x)) e. f(x) = (cos(x))3 = p m = p(m(x)) 5