Discussion #29 Functions Discussion #29 1/20 Topics • • • • • • • • Function Definition Notation Partial Functions Restrictions Overloading Composition Injections, surjections, bijections Inverses Discussion #29 2/20 Function Definition • A function is a special kind of binary relation. • A binary relation f A B is a function if for each a A there is a unique b B y 1 α 2 β 3 γ x Discussion #29 3/20 NOT Functions 1 α 2 β 3 γ f = {(1, α), (2, β)} “For each” violated y Some x’s do not have corresponding y’s x Discussion #29 4/20 NOT Functions 1 α 2 β 3 γ f = {(1, α), (2, β), (3, β), (3, γ)} uniqueness violated for 3 appears twice y Uniqueness violated for some x’s x Discussion #29 5/20 Functions with N-Dimensional Domains An (n+1)-ary relation f A1 A2 … An B is a function if for each < a1, a2, …, an> A1 A2 … An there is a unique b B. Discussion #29 <1,1> α <1,2> β <1,3> γ 6/20 Notation for Functions • We can use various notation for functions: for f = {(1, α),(2, β),(3, β)} Notation (x, y) f f : x→y y = f(x) Example (2, β) f f : 2→β β = f(2) • In the notation, x is the argument or preimage and y is the image. We can also have the image of a set of arguments. • For functions with n-ary domains, use <x0, x1, …, xn> in place of x. Discussion #29 7/20 Function Domain and Range • f:A→B – A is the domain space • same as the domain (since all elements participate) • dom f, dom(f), or domain(f) – B is the range space • may or may not be the same as the range, which is: – {y | x(y=f(x))} – All rhs values in pairs (all that get “hit”) – Bf • ran f, ran(f), range(f) • f : D1 D2 … Dn → Z • f : Dn → Z (when all domains are the same) Discussion #29 8/20 Partial Functions Remove the requirement that each a A must participate. Retain the uniqueness requirement. Partial Function: <1,1> α <1,2> β <1,3> γ NOT a Partial Function: <1,1> α <1,2> β <1,3> Discussion #29 γ Partial Function: (A Total Function is also a Partial Function.) <1,1> α <1,2> β <1,3> γ f = {(<1,2>, β),(<1,3>, β),(<1,3>, γ)} <1,3> not unique 9/20 Special Functions • Identity Function – IA : A → A – IA = {(x, x) | x A} • Constant Function –C:A→B – C = {(x, c) | x A c B } – Often A and B are the same • C:A→A • C= {(x, c) | x A c A} Discussion #29 10/20 Restrictions It is common to restrict the domain space of partial functions to be the actual domain. – log(x) is partial for R → R but total for R>0 → R – For “number of pregnancies” we may restrict the domain to mothers John 1 Mary 2 Sue Ken 3 – Sometimes we restrict for other reasons, e.g. mothers over 40 John 1 Mary 2 Sue Ken Discussion #29 3 11/20 Overloading • Overloading is like overloading in Java. • The same name can be used for different functions depending on the domain. • Examples a–b • Means number subtraction if a and b are numbers • Means set subtraction if a and b are sets a+b • Implemented differently for integers and reals • Could potentially be overridden and implemented by a programmer for very long integers Discussion #29 12/20 Composition of Functions a f 1 2 b 3 g(2) = α g(f(a)) = α g°f(a) = α f(b) = 2 α β 4 c f(a) = 2 g g(2) = α g(f(b)) = α • Composition is written “°” • Range space of f = domain space of g g°f(b) = α f(c) = 4 g(4) = β g(f(c)) = β g°f(c) = β Discussion #29 13/20 Injection Injection: “one-to-one” or “1-1” – xy(f(x) = f(y) x = y) – For f : A → B, the elements in B are “hit” at most once Injective NOT Injective 1 a 1 b b 2 3 2 c d 3 c d y y x Discussion #29 a x 14/20 Surjection Surjection: “onto” – yx(y = f(x)) – For f : A → B, the elements in B are all “hit” at least once Surjective NOT Surjective 1 2 3 4 a 1 2 b 3 4 c b c y y x Discussion #29 a { not “hit” x 15/20 Bijection Bijection: “one-to-one and onto” or “1-1 correspondence” – xy(f(x) = f(y) x = y) yx(y = f(x)) – For f : A → B, every B element is “hit” once and only once Bijective NOT Bijective 1 2 a 1 2 b 3 3 4 c NOT injective a b c y y x Discussion #29 NOT Surjective x 16/20 Notes on Bijection 1. |A| = |B| – – An “extra” B cannot be “hit” (not a surjection) An “extra” A requires that at least one B must be “hit” twice (not an injection) 2. If f is a bijection, swapping the elements of the ordered pairs is a function – – – – Called the inverse Denoted f-1 Is also a bijection f-1(f(x)) is the identity function, i.e. f-1(f(x)) = x. Discussion #29 17/20 Notes on Bijection (continued …) 3. The inverse of an injection is a partial function. If f : A →B is an injection, then f-1 is a partial function f 1 f-1 a a b b 2 c d 3 c d 1 2 3 4. Restricting the range space of an injective function to the range yields a bijection Remove b Discussion #29 18/20 Which is bigger? N or R[0..1]? Assume |N| = |R[0..1]|, then there exists a bijection: 1 0.34234… 2 0.34987… diagonalization 3 0.00040… But now there exists a number in R[0..1] such that d1 = not 3, d2 = not 4, d3 = not 0, … . Hence, not surjective and thus not bijective. Discussion #29 19/20 Which is bigger? N or Z? f(x) = g(y) = { { x odd: (x+1)/−2 x even: x/2 y negative: −2x−1 y positive: 2x x 0 1 2 3 4 y 0 −1 1 −2 2 Since g = f−1, there is a bijection from N to Z and thus |N| = |Z|. Countable if same cardinality as some subset of N. Alternatively, a set S is countable if there exists an injective function from S to N. Discussion #29 20/20