210 likes | 347 Views
Discussion #29 Functions. Topics. Function Definition Notation Partial Functions Restrictions Overloading Composition Injections, surjections, bijections Inverses. 1. α. 2. β. 3. γ. Function Definition. A function is a special kind of binary relation.
E N D
Topics • Function Definition • Notation • Partial Functions • Restrictions • Overloading • Composition • Injections, surjections, bijections • Inverses
1 α 2 β 3 γ 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 x
1 α 2 β 3 γ NOT Functions f = {(1, α), (2, β)} “For each” violated y Some x’s do not have corresponding y’s x
1 α 2 β 3 γ NOT Functions f = {(1, α), (2, β), (3, β), (3, γ)} uniqueness violated for 3 appears twice y Uniqueness violated for some x’s x
<1,1> α <1,2> β <1,3> γ Functionswith N-Dimensional Domains An (n+1)-ary relation f A1 A2 … An B is a function if for each < a1, a2, …, an> A1 A2 … Anthere is a unique b B.
Notation for Functions • We can use various notation for functions: for f = {(1, α),(2, β),(3, β)} • 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.
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)
<1,1> <1,1> <1,1> α α α <1,2> <1,2> <1,2> β β β <1,3> <1,3> <1,3> γ γ γ Partial Functions Remove the requirement that each a A must participate. Retain the uniqueness requirement. Partial Function: Partial Function: (A Total Function is also a Partial Function.) NOT a Partial Function: f = {(<1,2>, β),(<1,3>, β),(<1,3>, γ)} <1,3> not unique
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}
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 • Sometimes we restrict for other reasons, e.g. mothers over 40 John 1 Mary 2 Sue Ken 3 John 1 Mary 2 Sue Ken 3
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
Composition of Functions • Composition is written “°” • Range space of f = domain space of g g 1 α a f 2 β b 3 4 c
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 a a 1 1 b b 2 2 c c d d 3 3 y y x x
Surjection Surjection: “onto” • yx(y = f(x)) • For f : A → B, the elements in B are all “hit” at least once Surjective NOT Surjective a a 1 1 2 2 b b 3 3 c c 4 4 y y { not “hit” x x
Bijection NOT Surjective NOT injective 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 a a 1 1 2 2 b b 3 3 c c 4 y y x x
Notes on Bijection • |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) • 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.
Notes on Bijection (continued …) • The inverse of an injection is a partial function. If f : A →B is an injection, then f-1 is a partial function f f-1 a 1 1 a b b 2 2 c c d 3 3 d • Restricting the range space of an injective function to the range yields a bijection • Remove b
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.
Which is bigger? N or Z? { x odd: (x+1)/−2 x even: x/2 y negative: −2x−1 y positive: 2x f(x) = x y 0 0 1 −1 2 1 3 −2 4 2 { g(y) = 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.