• • Functions (Rosen, Section 2.3) TOPICS • Definition of Function • Domain, Codomain, Range • One-to-One Functions • Increasing Functions • • A B B A – • What’s the 1 difference between 2.4 2 codomain and range? 1.6 3 5.0 4 4.8 Range : {1,2,4,5} 5 • R 2.3 6 Range contains the • Z Domain Codomain codomain values that A B A maps to
• ƒ A ƒ • ƒ R ( Z A Successor function, ƒ succ (x) = x+1, on Z , maps a ■ number into the number following it. • ƒ f(1) = 2 ■ Only works on f(-17) = -16 ■ set Z f(a) Does NOT map to b ■ Predecessor function, ƒ pred (x) = x-1, on Z , maps a ■ number into the number before it. • f(1) = 0 ■ f(-17) = -18 ■ • • ƒ Z R – • ƒ ± • ƒ Need smallest integer Z R that is at least as large as 100/8 No Way! 100/8 = 12.5 √ But we don’t work with Say it ain’t so!! ½ a byte. ± √ ƒ So we need 13 bytes
• f • Z Z f(a) = f(b) a = b a b – f – ƒ ƒ • Z Z • 1 1 How dare they INCONCEIVABLE!! 2 2 have the same 3 • 3 codomain! 4 4 … Unique at last!! 9 … 16 • f • f(x) <= f(y) f(x) < f(y) , • – x < y So YES floor is – – x y f an increasing function • – BUT it is NOT 1.5 < 1.7 and floor(1.5) = 1 = floor(1.7) STRICTLY increasing. 1.2 < 2.2 and floor(1.2) = 1 < 2 = floor(2.2), • • … NO square is NOT an When mapping Z to Z or R to R: increasing function square(-2) = 4 > 1 = square (1) yet -2 < 1 UNLESS…. Domain is restricted to positive #’s
• • → Finds the minimum value between two integers • → – Math.min – Math.abs Finds the absolute value of a number
Recommend
More recommend