# Functions Reading: Epp Chp 7.1, 7.2, 7.4

## Presentation on theme: "Functions Reading: Epp Chp 7.1, 7.2, 7.4"— Presentation transcript:

Functions Reading: Epp Chp 7.1, 7.2, 7.4
CHAPTER 7 Functions Functions Reading: Epp Chp 7.1, 7.2, 7.4

Overview Functions Definitions Operations on Functions Definition
Visualization Tool Examples Notation Identity Function Definitions Domain, codomain, range Image, inverse image Let f:A ® B and let S Í A and T Í B. S Í InvImgf(Imgf(S)) Imgf(InvImgf(T)) Í T Operations on Functions Set related (È,Ç,-): If fÈg is a function, then f = g If fÇg is a function, then f = g If f-g is a function, then fÇg=f Inverse One-to-one and Onto Functions

1. Definition: Function Given a relation R from a set A to a set B, R is a function iff 1. "xÎA, \$yÎB, x R y 2. "xÎA, " y1,y2ÎB, x R y1 Ù x R y2 ® y1 = y2.

1. Definition: Function Given a relation R from a set A to a set B, R is a function iff 1. "xÎA, \$yÎB, x R y 2. "xÎA, " y1,y2ÎB, x R y1 Ù x R y2 ® y1 = y2. A function is a relation. It’s just a special kind of relation – a relation with 2 restrictions.

Extract the meaning from the logical expression.
1. Definition: Function Given a relation R from a set A to a set B, R is a function iff 1. "xÎA, \$yÎB, x R y 2. "xÎA, " y1,y2ÎB, x R y1 Ù x R y2 ® y1 = y2. A B R Every element in A must be associated with AT LEAST one element in B. Extract the meaning from the logical expression.

Extract the meaning from the logical expression.
1. Definition: Function Given a relation R from a set A to a set B, R is a function iff 1. "xÎA, \$yÎB, x R y 2. "xÎA, " y1,y2ÎB, x R y1 Ù x R y2 ® y1 = y2. A B R 2. An element in A can only be associated with AT MOST one element in B. Extract the meaning from the logical expression.

Extract the meaning from the logical expression.
1. Definition: Function Given a relation R from a set A to a set B, R is a function iff 1. "xÎA, \$yÎB, x R y 2. "xÎA, " y1,y2ÎB, x R y1 Ù x R y2 ® y1 = y2. A B R 1 and 2 taken together: Every element in A can only be associated with EXACTLY ONE element in B. Extract the meaning from the logical expression.

2. Visualisation Tool: Arrow Diagram
Given a relation R from a set A to a set B, R is a function iff 1. "xÎA, \$yÎB, x R y 2. "xÎA, " y1,y2ÎB, x R y1 Ù x R y2 ® y1 = y2. A B f Not a function

2. Visualisation Tool: Arrow Diagram
Given a relation R from a set A to a set B, R is a function iff 1. "xÎA, \$yÎB, x R y 2. "xÎA, " y1,y2ÎB, x R y1 Ù x R y2 ® y1 = y2. A B f Yes, it’s a function.

2. Visualisation Tool: Arrow Diagram
Given a relation R from a set A to a set B, R is a function iff 1. "xÎA, \$yÎB, x R y 2. "xÎA, " y1,y2ÎB, x R y1 Ù x R y2 ® y1 = y2. A B f Not a function

3. Examples Given a relation R from a set A to a set B, R is a function iff 1. "xÎA, \$yÎB, x R y 2. "xÎA, " y1,y2ÎB, x R y1 Ù x R y2 ® y1 = y2. Example 1: A {1,2,3} B {1,2,3} R = {(1,2)} R Í A x B Is R a function? No. (Cond 1) R = {(1,2),(2,3),(1,3)} {1,2,3} No. (Cond 2) R = {(1,1),(2,1),(3,1)} {1,2,3} Yes. {1,2,3,4} {1,2,3} R = {(1,1),(2,2),(3,3)} No. (Cond 1) {1,2,3} {1,2,3,4} R = {(1,1),(2,2),(3,3)} Yes.

3. Examples Given a relation R from a set A to a set B, R is a function iff 1. "xÎA, \$yÎB, x R y 2. "xÎA, " y1,y2ÎB, x R y1 Ù x R y2 ® y1 = y2. Example 2: Let R Í Q x Z such that… Q Z ? (i) x R y iff x = y. Q: Is R a function? A: No (1st Condition: ½ maps to nothing) (ii) (a/b) R c iff a.b = c. Q: Is R a function? A: Yes

3. Examples Given a relation R from a set A to a set B, R is a function iff 1. "xÎA, \$yÎB, x R y 2. "xÎA, " y1,y2ÎB, x R y1 Ù x R y2 ® y1 = y2. Example 3: Let R Í Z x Z such that… (i) x R y iff y = x2. Q: Is R a function? A: Yes. Z 3 ? 1 -1 (ii) x R y iff x = y2. Q: Is R a function? A: No. (1st and 2nd Condition violated)

3. Examples Functions in real life: Hamming distance function.
Encoding/decoding functions. Boolean functions. A program is a function.

4. Notation We usually use “f,g,h,F,G,H” to denote functions.
If the relation f Í A x B is a function, we write it as: f : A ® B If there is a way to compute yÎB from any given xÎA, we usually write ‘f(x)’ in place of ‘y’. Eg. 1: F Í Z x Z , x F y iff y = x2. ‘F’ is a function. We will write it as: F : Z ® Z, F(x) = x2 Eg. 2: F Í Z x Z , x F y iff y = x2 + 2x + 1 We will write it as: F : Z ® Z, F(x) = x2 + 2x + 1 Eg. 3: F Í Z x {0,1}, a F b iff (a is even ® b=1) Ù (a is odd ® b=0) F : Z ® {0,1}, F(x) = 1, if x is even 0, otherwise

4. Notation We usually use “f,g,h,F,G,H” to denote functions.
If the relation f Í A x B is a function, we write it as: f : A ® B If there is a way to compute yÎB from any given xÎA, we usually write ‘f(x)’ in place of ‘y’. Therefore, the definitions instead of… 1. "xÎA, \$yÎB, x R y 2. "xÎA, "y1,y2ÎB, x R y1 Ù x R y2 ® y1=y2. 1. "xÎA, \$yÎB, y = f(x) 2. "xÎA, "y1,y2ÎB, y1=f(x) Ù y2=f(x) ® y1=y2. … can be also expressed as…

5. The identity function. The identity function on any given set, is a function that maps every element to itself. idA : A ® A, "xÎA, idA(x) = x

Overview Operations on Functions Set related (È,Ç,-): Inverse
Definition Visualization Tool Examples Notation Identity Function Definitions Domain, codomain, range Image, inverse image Let f:A ® B and let S Í A and T Í B. S Í InvImgf(Imgf(S)) Imgf(InvImgf(T)) Í T Operations on Functions Set related (È,Ç,-): If fÈg is a function, then f = g If fÇg is a function, then f = g If f-g is a function, then fÇg=f Inverse One-to-one and Onto Functions

6. Definition: domain, codomain, range
Given a function: f : A ® B, The set A is known as the domain of f. The set B is known as the codomain of f. The set { yÎB | \$xÎA, y=f(x)} is known as the range of f. A B f

6. Definition: domain, codomain, range
Given a function: f : A ® B, The set A is known as the domain of f. The set B is known as the codomain of f. The set { yÎB | \$xÎA, y=f(x)} is known as the range of f. Domain(f) A f B

6. Definition: domain, codomain, range
Given a function: f : A ® B, The set A is known as the domain of f. The set B is known as the codomain of f. The set { yÎB | \$xÎA, y=f(x)} is known as the range of f. Codomain(f) A f B

6. Definition: domain, codomain, range
Given a function: f : A ® B, The set A is known as the domain of f. The set B is known as the codomain of f. The set { yÎB | \$xÎA, y=f(x)} is known as the range of f. Range(f) NOTE: range(f) Í codomain(f) A f B

6. Definition: domain, codomain, range
Given a function: f : A ® B, The set A is known as the domain of f. The set B is known as the codomain of f. The set { yÎB | \$xÎA, y=f(x)} is known as the range of f. Example 1: f : Z ® Z+, f(x) = |2x| a. domain(f) = Z b. codomain(f) = Z+ c. range(f) = positive even numbers: {2x | x Î Z+}

6. Definition: domain, codomain, range
Given a function: f : A ® B, The set A is known as the domain of f. The set B is known as the codomain of f. The set { yÎB | \$xÎA, y=f(x)} is known as the range of f. Example 2: Let f : Z ® Z, f(x) = 2x + 1; g : Z ® Z, g(x) = 2x - 1 Then range(f) = range(g). Range(f) = 2x+1 = 2(x+1) – 1 = Range(g) "xÎZ, f(x) = g(x+1)

7. Definition: Image, Inverse Image.
Given a function: f : A ® B, and S Í A The image of S is defined as: Imgf(S) = { yÎB | \$xÎS, y=f(x)} A B f

7. Definition: Image, Inverse Image.
Given a function: f : A ® B, and S Í A The image of S is defined as: Imgf(S) = { yÎB | \$xÎS, y=f(x)} A B f S Image of S NOTE: Imgf(S) Í range(f) Í codomain(f)

7. Definition: Image, Inverse Image.
Given a function: f : A ® B, and S Í A The image of S is defined as: Imgf(S) = { yÎB | \$xÎS, y=f(x)} Given a function: f : A ® B, and T Í B The inverse image of T is defined as: InvImgf(T) = { xÎA | \$yÎT, y=f(x)} A B f T Inverse image of T

7. Definition: Image, Inverse Image.
Given a function: f : A ® B, and S Í A The image of S is defined as: Imgf(S) = { yÎB | \$xÎS, y=f(x)} Given a function: f : A ® B, and T Í B The inverse image of T is defined as: InvImgf(T) = { xÎA | \$yÎT, y=f(x)} Example: f : Z ® Z+, f(x) = |x| a. Imgf({10,-20}) = {10,20} b. InvImgf({10,20}) = {10, 20, -10, -20}

7. Definition: Image, Inverse Image.
Given a function: f : A ® B, and S Í A The image of S is defined as: Imgf(S) = { yÎB | \$xÎS, y=f(x)} or yÎImgf(S) iff \$xÎS and y=f(x) Given a function: f : A ® B, and T Í B The inverse image of T is defined as: InvImgf(T) = { xÎA | \$yÎT, y=f(x)} xÎInvImgf(T) iff \$yÎT and y=f(x) Axiomatic definition

7.1 Theorem: Image, Inverse Image.
Given any function: f : A ® B, S Í A, T Í B S Í InvImgf(Imgf(S)) Imgf(InvImgf(T)) Í T Proof of (1): (Use diagrams to help visualise!) A B f

7.1 Theorem: Image, Inverse Image.
Given any function: f : A ® B, S Í A, T Í B S Í InvImgf(Imgf(S)) Imgf(InvImgf(T)) Í T Proof of (1): (Use diagrams to help visualize!) S A f B

7.1 Theorem: Image, Inverse Image.
Given any function: f : A ® B, S Í A, T Í B S Í InvImgf(Imgf(S)) Imgf(InvImgf(T)) Í T Assume xÎS Proof of (1): Then \$yÎB such that y = f(x) (Since f is a function) Imgf(S) S Therefore yÎImgf(S) (Defn: yÎImgf(S) iff \$xÎS and y=f(x)) y x Therefore yÎImgf(S) and y = f(x) Therefore xÎInvImgf(Imgf(S)) A f B

7.1 Theorem: Image, Inverse Image.
Given any function: f : A ® B, S Í A, T Í B S Í InvImgf(Imgf(S)) Imgf(InvImgf(T)) Í T Assume xÎS Proof of (1): Then \$yÎB such that y = f(x) (Since f is a function) Imgf(S) Therefore yÎImgf(S) (Defn: yÎImgf(S) iff \$xÎS and y=f(x)) y x Therefore yÎImgf(S) and y = f(x) Therefore xÎInvImgf(Imgf(S)) A f B (Defn:xÎInvImgf(T) iff \$yÎT and y=f(x))

7.1 Theorem: Image, Inverse Image.
Given any function: f : A ® B, S Í A, T Í B S Í InvImgf(Imgf(S)) Imgf(InvImgf(T)) Í T …Proof of (2) left as an exercise… (Again, the skill that you must pick up is that you must use diagrams wherever possible, to help visualize the problem and use it to help you reason about proofs)

Overview Operations on Functions Set related (È,Ç,-): Functions
If fÈg is a function, then f = g If fÇg is a function, then f = g If f-g is a function, then fÇg=f Inverse One-to-one and Onto Functions Functions Definition Visualization Tool Examples Notation Identity Function Definitions Domain, codomain, range Image, inverse image Let f:A ® B and let S Í A and T Í B. S Í InvImgf(Imgf(S)) Imgf(InvImgf(T)) Í T

8. Operations on Functions.
A function is a (special) relation. A relation is a set (of ordered pairs). Therefore, all definitions and operations on sets and relations are extended over to functions.

"xÎA, y1=f(x) Ù y2=g(x) ® y1=y2
8.1 Equality of Functions Given 2 functions, f : A ® B, g : A ® B, f = g iff f Í g and g Í f Or, in cases where y can be computed directly from x: f = g iff "xÎA, y1=f(x) Ù y2=g(x) ® y1=y2 Which is equivalent to: f = g iff "xÎA, f(x) = g(x)

8.2 Union, Intersection, Difference
Given 2 functions, f : A ® B, g : A ® B, f Èg, f Çg, f-g are defined as accordingly in set theory (since functions are sets). …Or, in cases where y can be computed directly from x: (fÈg)(x) = y iff y = f(x) or y = g(x) (fÇg)(x) = y iff y = f(x) and y = g(x) (f-g)(x) = y iff y = f(x) and y ¹ g(x) NOTE: f Èg, f Çg, f-g need not necessarily be functions. At most, one can only conclude that f Èg, f Çg, f-g are relations. In order to assert that they are functions, one must prove that the 2 conditions necessary for functions are true.

8.2 Union, Intersection, Difference
Theorem: Given 2 functions f and g from A to B, If f È g is a function, then f = g If f Ç g is a function, then f = g If f-g is a function, then f Ç g = f Proof of (1): (Direct proof: f = g iff "xÎA, f(x) = g(x) A B f A B g y1 x x y2 A B f È g But fÈg is a function! Defn:y1= (fÈg)(x) and y2= (fÈg)(x) then y1=y2. y2 y1 x

8.2 Union, Intersection, Difference
Theorem: Given 2 functions f and g from A to B, If f È g is a function, then f = g If f Ç g is a function, then f = g If f-g is a function, then f Ç g = f Proof of (1): (Direct proof: f = g iff "xÎA, f(x) = g(x) Let xÎA. Since f is a function, then \$y1ÎB, y1= f(x), (x,y1)Îf Since g is a function, then \$y2ÎB, y2= g(x), (x,y2)Îg Therefore (x,y1) Î f Èg and (x,y2) Î f Èg. i.e. y1= (f Èg)(x) and y2 = (f Èg)(x) But since fÈg is a function, then y1=y2 . Therefore f(x) = g(x) (By definition of function equality)

8.2 Union, Intersection, Difference
Theorem: Given 2 functions f and g from A to B, If f È g is a function, then f = g If f Ç g is a function, then f = g If f-g is a function, then f Ç g = f Proof of (3): (By contradiction) A B f-g x A B f x y A B g x y A B f Ç g x y

8.2 Union, Intersection, Difference
Theorem: Given 2 functions f and g from A to B, If f È g is a function, then f = g If f Ç g is a function, then f = g If f-g is a function, then f Ç g = f Proof of (3): (By contradiction) Assume that f Ç g ¹ f Then by definition, \$(x,y) Î f Ç g That means that (x,y) Î f and (x,y) Î g That means that (x,y) Ï (f – g). But f – g is a function! "xÎA, \$yÎB, y = (f – g)(x). So there must be a (x,y) Î (f – g) => Contradiction! Therefore f Ç g = f.

8.2 Union, Intersection, Difference
Theorem: Given 2 functions f and g from A to B, If f È g is a function, then f = g If f Ç g is a function, then f = g If f-g is a function, then f Ç g = f Proof of (2) left as an exercise Similar to Proof of (1).

8.3 Definition: Inverse of a function
Given a function, f : A ® B, the inverse of a function is defined in the same way as that of a relation: f-1 = { (y,x) | (x,y) Îf } NOTE: f-1 need not necessarily be a function. It is first and foremost, a relation. In order to assert that they are functions, one must prove that the 2 conditions necessary for functions are true. So f-1 Í B x A If f-1 is a function, then we write: f-1 : B ® A … and then say that: f(x) = y iff f-1(y) = x

8.3 Definition: Inverse of a function
Find the inverse of the function f(x) = (1+x)/(1-x). Ans: Let y = (1+x)/(1-x). Express x in terms of y. Therefore: y – yx = 1 + x Therefore: y – 1 = yx + x Therefore: x(y+1) = y–1 Therefore: x = (y–1)/(y+1) Therefore: f-1(y) = (y–1)/(y+1) i.e. f-1(x) = (x–1)/(x+1)

Overview Operations on Functions Set related (È,Ç,-): Functions
If fÈg is a function, then f = g If fÇg is a function, then f = g If f-g is a function, then fÇg=f Inverse One-to-one and Onto Functions Functions Definition Visualization Tool Examples Notation Identity Function Definitions Domain, codomain, range Image, inverse image Let f:A ® B and let S Í A and T Í B. S Í InvImgf(Imgf(S)) Imgf(InvImgf(T)) Í T

One-to-One and Onto Functions
Definition A function f: X → Y is one-to-one (also called injective) if and only if, for any x1, x2  X, if f(x1) = f (x2), then x1 = x2. (Alternatively, by contraposition, if x1  x2, then f(x1)  f(x2), i.e. the images of distinct elements in X are always distinct elements in Y.) Definition A function f: X → Y is onto (also called surjective) if and only if for all y  Y, there exists x  X such that y = f(x). (Alternatively, every element in Y is the image of at least one element in X.) Now let’s consider some earlier examples in light of these definitions.

One-to-One and Onto Functions (cont’d)
Consider the following previously-discussed functions: 1. Let X = Y = {1, 2, 3} and f: X → Y be given by f(x) = x. Then f is both one-to-one and onto, i.e. distinct elements in X are always “mapped” to distinct elements in Y, and every element in Y is the image of an element (itself) in X. Let X = {-2, -1, 0, 1, 2}, Y = {0, 1, 2, 3, 4} and f: X → Y be given by f(x) = x2. Then f is not one-to-one, since (for example) f(-2) = f(2) = 4. Also, f is not onto, since (for example) y = 3 is not the image of any x  X. In the arrow diagram at right, h is not one-to-one, since h(x1) = h(x3) = y3. Likewise, h is not onto, since y2 is not the image of any element in X. h X → Y x1   y1 x2   y2 x3   y3

One-to-One and Onto Functions (cont’d)
s(n) = (-1)n+1/n s: Z+ → Q – 1 but not onto r(x) = |x| r: R → R neither 1 – nor onto t(n) = n(mod 2) t: Z → {0, 1} onto but not 1 - 1 u(x) = x1/2 u: R+ → R+ both 1 – 1 and onto

One-to-One Correspondences and Inverse Functions
Definition A function f: X → Y is a one-to-one correspondence (also called a bijection) if and only if f is both one-to-one and onto. Of the previous examples, only 1 function is a one-to-one correspondence: u: R+ → R+ where u(x) = x1/2. Two primary applications for one-to-one correspondences: 1. They are used to prove that two sets have the same number of elements, i.e. if a 1 – 1 correspondence exists between two sets, they have the same cardinality. 2. One-to-one correspondences are the only functions for which inverse functions exist.

One-to-One Correspondences and Inverse Functions (cont’d)
Example Show that the odd integers have the same cardinality as the integers Z. Let O = {2k + 1 | k  Z} be the set of odd integers. Define a function f: Z → O by f(k) = 2k + 1. Every member of O is therefore the image of an element in Z, i.e. f is onto. Assume f(k1) = f(k2), i.e. 2k1 + 1 = 2k But then k1 = k2, i.e. f is one-to-one. It follows that f is a one-to-one correspondence, and hence n(O) = n(Z) = א0.

One-to-One Correspondences and Inverse Functions (cont’d)
Example Find the inverse function for f: Z → O where f(k) = 2k + 1. The given function has just been shown to be a one-to-one correspondence. It follows that, for any n  O such that n = f(k) = 2k + 1, then k = (n – 1)/2, i.e. the required inverse function is f -1: O → Z, where f -1(n) = (n – 1)/2 = k. f k+1=n f -1 (n–1)/2=k f (n–1)/2=k f k+1=n