1 / 51

Functions

Functions. Read Section 1.8. 1. Outline. Introduction: definitions, example and terminology, image of a subset of domain, sum and product of functions One-to-one functions: strictly increasing, decreasing functions Onto functions Bijections: identity functions Graphs of Functions

dustin
Download Presentation

Functions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Functions Read Section 1.8 MSU/CSE 260 Fall 2009 1

  2. Outline • Introduction: definitions, example and terminology, image of a subset of domain, sum and product of functions • One-to-one functions: strictly increasing, decreasing functions • Onto functions • Bijections: identity functions • Graphs of Functions • Inverse Functions • Compositions of Functions • Some Important Functions: Floor, Ceiling and Factorial functions 2 MSU/CSE 260 Fall 2009

  3. Function • Example • Consider your final grades in CSE 260. Your grades will be one of the values from the set {4, 3.5, 3, 2.5, 2, 1.5, 1, 0} • What kind of properties does this assignment have? • Consider the courses you are taking this semester. { (A123, CSE 260), (A123, CSE 232), (A123, MTH 234), (A123, DYLANTHOMAS 111)} • What kind of properties does this assignment have? 3 MSU/CSE 260 Fall 2009

  4. Introduction • Definition:Let A,B be sets. A function f from A to B, denotedf: A→ B, is an assignment where each element of A is assigned exactly one element of B. • Notation: • f: A→ B • We writef (a) = b, if b is the element of B assigned under f to the element aof A. • We also say fmapsA to B • Formally, f is a function from A to B if and only if xA !yBf(x) = y. where ! is the uniqueness quantifier. 4 MSU/CSE 260 Fall 2009

  5. Example f: A→ B Students Grades 4 A 3 Adams B 2 Marie Stevens 1 f(Adams)=1 f(Marie)=4 f(Stevens)=3 f(Sara)=3 Sara 0 5 MSU/CSE 260 Fall 2009

  6. Domain, Co-domain, … • Definition:Let fbe a function from A to B,that is, f: A→ B. Then A is called the domain of f, and B is the codomainof f. • If f(a) = b, then • bis called the image of a, and • a is apre-imageof b. • The range of f is the set of all images of elements of A. • How are codomain and range related? • Range is a subset of the codomain 6 MSU/CSE 260 Fall 2009

  7. Example f (Adams)=1 f (Marie)=4 f (Stevens)=3 f (Sara)=3 f: A→ B Students Grades 4 3 Adams 2 A Marie B Stevens 1 Sara 0 • The image of ‘Marie’ is 4; the pre-images of 3 are ‘Stevens’ and ‘Sara’; the range of fis {1, 3, 4}. 7 MSU/CSE 260 Fall 2009

  8. Sum, Products of real-valued Functions • Definition:Let f1 and f2be functions from A to R. Then f1 + f2 and f1 f2 are also functions from A to R,defined as: • (f1 + f2)(x) = f1(x) + f2(x) • (f1  f2)(x) = f1(x) f2(x) • Note that if f1 and f2 do not have the same domain, the above operations do not make sense. 8 MSU/CSE 260 Fall 2009

  9. Image of a subset of a domain • Definition:Let f be a function from A to B, and letSbe a subset of A. Theimage of S, denotedf (S), is the subset of B consisting of the images of the elements of S. • Formally: f (S) = { f (s) | s S}. • Note that f (A) is the range of f . • In the previous Example, • f ({Adams, Sara}) = {3, 1} 9 MSU/CSE 260 Fall 2009

  10. a 2 b 3 c 4 One-to-one Functions • Definition: A function f from Ato B is said to be one-to-one, or injective, if and only if distinct elements of the domain have distinct images. That is, xA yAf (x) = f (y) →x = y. 1 10 MSU/CSE 260 Fall 2009

  11. a b c 2 d 3 Onto Functions • Definition:A function f from Ato B is said to be onto, or surjective, if and only if its range and codomain are the same. That is, yB xAf(x) = y. 1 11 MSU/CSE 260 Fall 2009

  12. a b c 3 d 4 Bijections • Definition:A function f: A→ B is a bijection, or one-to-one correspondence, if it is both one-to-one and onto. • Note that the cardinalities (when dealing with finite sets) of domain and codomain of a bijection are equal. 1 2 12 MSU/CSE 260 Fall 2009

  13. a a b b c c 3 d d 4 1 a a b b 2 c 3 c 3 d 4 4 Summary of Function Types 1-to1 but not onto onto but not 1-to-1 both 1-to-1 and onto; bijection 1 1 a 2 1 2 b 3 2 c 4 3 1 Not a function 2 Neither 1-to-1 nor onto 13 MSU/CSE 260 Fall 2009

  14. Monotonic Functions • Definition:Let A and B be subsets of R, the set of real numbers. A function f: A→ B is strictlyincreasing if xA yAx < y→f (x) < f (y). • f: A→ B is strictly decreasing ifxA yAx < y→f (x) > f (y). • Note that strictly increasing, or strictly decreasing (strictly monotone) functions must be one-to-one. 14 MSU/CSE 260 Fall 2009

  15. Inverse Function • Definition:Let function f: A→ B be a bijection. The inverse function of f, denoted f -1, is the function, f -1 : B→ A, that assigns to each element b of B the element a of A such that f (a) = b. • aA bBf(a)= b →f -1(b) = a. • f is called invertible. a 1 f -1(1) = d f -1(2) = b f -1(3) = a f -1(4) = c b 2 f c 3 d 4 15 MSU/CSE 260 Fall 2009

  16. Inverse Function… • Example: Let f : Z→Z, where f (x) = x + 1. • f is a bijection; what is f -1? • Suppose f (x) = y; then x + 1= y; so x = y - 1= f -1(y) f -1(x) = x ­ 1. 16 MSU/CSE 260 Fall 2009

  17. Identity Function • Let A be a set. The identity function on A is the function ιA : A→A, wherex  AιA (x) = x. • Notes: • ιAassigns each element of A to itself. • ιA is a bijection. 17 MSU/CSE 260 Fall 2009

  18. Characteristic and Constant Functions • Let A be a subset of universe U. The characteristic functionfA : U → {0, 1}, is such that fA(x) = 1 if x  A and fA(x) =0 if ¬ (x  A ) • Let A be a set. The constant functionf : A→ {t} maps each element of A to the same value t. 18 MSU/CSE 260 Fall 2009

  19. a b c d Compositions of Functions • Definition:Let g be a function from A to Band fa function from B to C, that is, g: A→ Bf: B→ C • The composition of fand g, denoted f o g, is function from A to C, defined as followsxA ( f o g)(x)= f (g(x)). A={a, b, c, d} B={q, p , k, v} C={1, 2, 3, 4} f q (f o g)(a) = 2 (f o g)(b) = 3 (f o g)(c) = 1 (f o g)(d) = 2 1 p g 2 k v 3 4 19 MSU/CSE 260 Fall 2009

  20. Composition of Functions f o g g f B B B B B B c c c c c c c c A A A A 20 MSU/CSE 260 Fall 2009

  21. Example • Consider the two functions f :Z→Z,where f (x) = 2x + 3 g:Z→Z, whereg (x) = 3x + 2. • What are f o g, andg o f? • f o g:Z→Z, where (f o g)(x) = f (g(x)) = f (3x + 2) = 2(3x + 2) + 3 = 6x +7 • g o f:Z→Z, where (g o f )(x) = g( f (x)) = g (2x + 3) = 3(2x + 3) + 2 = 6x + 11 21 MSU/CSE 260 Fall 2009

  22. Example 22 MSU/CSE 260 Fall 2009

  23. Example 23 MSU/CSE 260 Fall 2009

  24. Example…. 24 MSU/CSE 260 Fall 2009

  25. Graph of a Function • Definition: Let f: A→ B. The graph of f is the set of ordered pairs Gf = {(x, f (x))| x  A}. 25 MSU/CSE 260 Fall 2009

  26. Graph of a Function…. • The graph of the functionf :Z→Z, wheref (n) = 2n + 1, is Gf = {(n, 2n + 1) | n Z} (2,5) f (n) (1,3) (0,1) n (-1,-1) 26 MSU/CSE 260 Fall 2009

  27. Important Integer Functions • Whole numbers constitute the backbone of discrete mathematics. We often need to convert fractions or arbitrary real numbers to integers. These integer functions will help us do that. • Besides the identity function, some important functions are: • The floor function, • The ceiling function, • Themod function. 27 MSU/CSE 260 Fall 2009

  28. Floor Function • Definition:The floorfunction from R to Zassigns to the real number x, the largest integer ≤ x. The value of the floor function at x is denoted by x. • xR nZ x= n  nx < n + 1. • Examples: • 18 = 18 • 3.75 = 3 • – 4.5 = – 5 28 MSU/CSE 260 Fall 2009

  29. Ceiling Function • The ceiling function from R to Zassigns to the real number x the smallest integer ≥x. The value of the ceiling function at x is denoted by x. • xR nZx= n  n– 1 <x n. • xRx– 1 <xx  x< x + 1. • Examples: • 18= 18 • 3.75 = 4 • – 4.5 = – 4 29 MSU/CSE 260 Fall 2009

  30. Floor and Ceiling Functions, recap * * x x 0 x x 30 MSU/CSE 260 Fall 2009

  31. Properties of xandx • xR nZx= n  nx < n + 1. • xR nZx= n  n– 1 <x n. • xR nZx= n  x– 1 <n  x. • xR nZx= n  xn < x +1. • xRx– 1 <xx  x< x + 1. • xR–x= –x • xR–x= –x • xR mZx + m= x+ m • xR mZx + m= x+ m * * x x 0 x x 31 MSU/CSE 260 Fall 2009

  32. Example 32 MSU/CSE 260 Fall 2009

  33. Example: Solution 33 MSU/CSE 260 Fall 2009

  34. Integer Functions MSU/CSE 260 Fall 2009 34

  35. 35 MSU/CSE 260 Fall 2009

  36. Example 36 MSU/CSE 260 Fall 2009

  37. Example: Solution 37 MSU/CSE 260 Fall 2009

  38. The mod Function • When dividing an integer n by a number m , the quotient of the division is n/m. What about a simple notation for the remainder of this division? • That’s what the modfunction is about: • n mod m • m is called modulus • n = m n/m + n mod m quotient remainder 38 MSU/CSE 260 Fall 2009

  39. Example • Formally, the modfunction is a mapping: mod :ZZ+ →N where nmodm = n – m  n/m • Examples:5 mod 3 = 5 – (3 5/3 ) = 5 – (3 1.6 ) = 5 – (3 1 ) = 2 39 MSU/CSE 260 Fall 2009

  40. Example • nmodm = n –(m  n/m ) • Examples: -5 mod 3 = -5 – (3 -5/3 ) = -5 – (3 -1.6 ) = -5 – (3 (-2)) = 1. • We also write: 5  2 mod 3, 9  0 mod 3, -5  1 mod 3. 40 MSU/CSE 260 Fall 2009

  41. mod Function m 0 + – 1 m-1 2 41 MSU/CSE 260 Fall 2009

  42. List Search Methods • Problem: Given a list of elements, how fast can we decide whether or not a given input element belongs to the list? • Linear search • Binary search; need to sort the list first • Hash table 42 MSU/CSE 260 Fall 2009

  43. Hash Functions MSU/CSE 260 Fall 2009 43

  44. Hash Functions • A hash function h: keys→ integersmaps “keys” to “small” integers (buckets) • Ideal features: • The function should be easy to compute • The range values should be “evenly” distributed • Given an image, it shouldnot be “easy” to find its pre-image • Applications • Searching/indexing • Information hiding • File signature 44 MSU/CSE 260 Fall 2009

  45. Hashing for Indexing • A hash function h: keys→ integersmaps “keys” to “small” integers (buckets) • Ideally this mapping is done in a “random” manner so that the bucket values are evenly distributed despite irregularities in the keys. • For simplicity, we will assume that the keys are also integers, denoted by k, and the number of buckets is demoted by m. Note that the buckets are indexed 0 through m - 1. 45 MSU/CSE 260 Fall 2009

  46. Example • Storing CSE 260, both sections, PIDs\A • Using Hash Function h(PID)=kmod31 46 MSU/CSE 260 Fall 2009

  47. Simple Hash Functions • h(k) = k mod m • Suggestion:Choose m to be a prime number that isn’t close to a power of 2. • h(k) = k(k + 3) mod m 47 MSU/CSE 260 Fall 2009

  48. Hashing for Hiding Information • Here, the hash function maps a string to another string with the property of being very difficult to reverse the result of the hash. • Used in hiding user’s password 48 MSU/CSE 260 Fall 2009

  49. How password is checked. 49 MSU/CSE 260 Fall 2009

  50. Hashing for file signature • The hash function maps a large string (e.g., a file) to a fixed size string called digest • Examples: • MD5 (Message-Digest algorithm 5), gives a 128-bit hash (digest) • SHA-1 (Secure Hash Algorithm) is a most commonly used from SHA series of cryptographic hash functions, designed by the National Security Agency • SHA-1 produces the 160-bit hash value. Original SHA (or SHA-0) also produce 160-bit hash value, but SHA-0 has been withdrawn by the NSA shortly after publication and was superseded by the revised version commonly referred to as SHA-1. The other functions of SHA series produce 224-, 256-, 384- and 512-bit hash values. 50 MSU/CSE 260 Fall 2009

More Related