Section 4.2 Functions
Announcement Exam #3 has been rescheduled –Monday, April 4 th –Chapters 3 and 4 –Practice sheet for Chapter 3 now posted.
Activity 1 Let f: X → Y as shown by : What is the domain of f? What is the target of f? What is the range of f? What is f(a)? f(b)? f(c)?
Review What is a function?
Definition of a function A function f from a set X to a set Y, denote f: X → Y, is a relation from X, the domain to Y, the target (or co-domain) that satisfies two properties: 1.Every element in X is related to some element in Y 2.No element in X is related to more than one element in Y
Consider the following Let N = {Adams, Epp, Stevens, Rosen, Smedley} L = {A, B, C, D, F} g : N → L such that the mapping indicates the student’s grade in the class. Is g a function?
Non-functions What kind of situations would need to occur for this to not be a valid function.
We sometimes write functions as a set of ordered pairs. g = {(Adams, A), (Epp, C), (Stevens, B), (Rosen, A), (Smedley, F)}
Activity #2 Represent f as a set of ordered pairs.
Activity 3 Consider: L = {1,2,3,4,5} R = {A,B,C,D,F} Which of the following are functions from L to R? 1.{(1,A),(2,B),(3,C),(4,D),(5,F)} 2.{(2,A),(2,B),(3,C),(4,D),(5,F)} 3.{(1,A),(2,A),(3,B),(4,B),(5,B)} 4.{(1,5),(2,4),(3,3),(4,2),(5,1)} 5.{(2,A),(3,B),(4,B),(5,B)}
Activity 4 Find all of the functions from X = {a,b} to Y={u,v} Find all of the functions from X = {a,b} to Y={u} How many functions would exist from X = {a,b,c,d} to Y={u,v,x} How does this relate back to Cartesian products of sets?
Common Functions in CS Floor function floor: R → Z floor(x) = the largest integer y such that y≤x
Common Functions in CS Ceiling function ceiling: R → Z ceiling(x) = the smallest integer y such that x≤y
Common Functions in CS Encoding and Decoding functions E: bitString → bitString D: bitString → bitString
Common Functions in CS Encoding and Decoding functions E(s) = the string obtained from s by replacing each bit of s by the same bit written three times D(t) = the string obtained from t by replacing each consecutive triple of three bits by a single copy of that bit
Common Functions in CS Encoding and Decoding functions E(s) = the string obtained from s by replacing each bit of s by the same bit written three times D(t) = the string obtained from t by replacing each consecutive triple of three bits by whichever bit is most frequent.
Common Functions in CS The Hamming Distance H: bitString,bitString → Z H(s,t) = the count of the number of positions in which s,t have different values