10/20/2016
FUNCTION
Let X and Y are nonempty sets.
A function (f) from X to Y is a relation from X to
[Part 2] Y having a properties:
o The domain of f is X
FUNCTIONS o If (x,y), (x,y’) f, then y =y’
Semester (1) : 2015/2016
1 2
Relations vs Functions Relations vs Functions
3 4
Domain, Co-domain, Range Example
Given the relation, f = { (1,a), (2,b), (3,a) } from
A function from X to Y is denoted, f : X → Y X = { 1, 2, 3 } to Y= { a, b, c } is a function from
The domain of f is the set X. X to Y. State the domain and range.
The set Y is called the co-domain or target of f.
Solution:
The set { y | (x,y) f } is called the range.
The domain of f is X
The range of f is {a, b}
5 6
1
10/20/2016
Example (cont.) Example
7 8
Example Notation of function: f(x)
For the function, f = {(1,a), (2,b), (3,a)}
We may write:
f (1)=a, f (2)=b, f (3)=a
Notation f (x) is used to define a function.
9 10
Example One-to-One Function
o Defined: f (x) = x2
o f (2) = 4, f (-3.5) =12.25, f (0) = 0
o f = {(x, x2 )| x is a real number}
11 12
2
10/20/2016
Example Example (cont.)
• The function, f = { (1,a), (2,b), (3,a) } from X = {
• The function, f = { (1,b), (3,a), (2,c) } from X = { 1, 2, 3 } to Y = { a, b, c} is NOT one-to-one.
1, 2, 3 } to Y = { a, b, c, d } is one-to-one. • f (1)= a = f (3)
13 14
Example Solution
15 16
Example Solution
17 18
3
10/20/2016
Onto Function Example
• The function, f = { (1,a), (2,c), (3,b) } from X = {
If f is a function from X to Y and the range of f
1, 2, 3 } to Y = { a, b, c } is one-to-one and onto
is Y, f is said to be onto Y (or an onto function Y.
or a surjective function)
For every y Y, there exists at least one x X
such that f (x) = y
y Y x X ( f (x) = y )
19 20
Example Bijection Function
A function, f is called one-to-one
• The function, f = { (1,b), (3,a), (2,c) } is not
correspondence (or bijective/bijection) if f is
onto Y = {a, b, c, d}
both one-to-one and onto.
Example:
21 22
Exercise Inverse Function
Determine which of the relations f are functions from the set X to
the set Y. In case any of these relations are functions, determine if Let f: X→Y be a function.
they are one-to-one, onto Y, and/or bijection.
a) X = { -2, -1, 0, 1, 2 } , Y = { -3, 4, 5 } and The inverse relation f -1 Y×X is a function
f = { (-2,-3), (-1,-3), (0,4), (1,5), (2,-3) } from Y to X, if and only if f is both one-to-one
and onto Y.
b) X = { -2, -1, 0, 1, 2 } , Y = { -3, 4, 5 } and
f = { (-2,-3), (1,4), (2,5)}
c) X = Y= { -3, -1, 0, 2 } and
f = { (-3,-1), (-3,0), (-1,2), (0,2), (2,-1) }
23 25
4
10/20/2016
Example Example
o The function, f (x) = 9x + 5 for all x R (R is the set
f = {(1,a),(2,c),(3,b)} f -1= {(a,1),(c,2),(b,3)} of real numbers).
o This function is both one-to-one and onto.
o Hence, f –1 exists.
o Prove:
Let (y, x) f -1, f -1(y) = x
(x,y) f, y = 9x + 5
x = (y-5)/9
f -1(y) = (y-5)/9
26 27
Exercise Composition
Suppose that g is a function from X to Y and f
is a function from Y to Z.
The composition of f with g,
fg
is a function
(f g)(x) = f (g(x))
from X to Z.
28 29
Example Example (cont.)
o Given, g = { (1,a), (2,a), (3,c) }
a function from X = {1, 2, 3} to Y = {a, b, c}
and,
f = { (a,y), (b,x), (c,z) }
a function from Y to Z = { x, y, z }.
o The composition function from X to Z is the function
f ο g = { (1,y), (2,y), (3,z) }
30 31
5
10/20/2016
Example Example
f (x) = log3 x and g (x) = x4
f (g (x)) = log3 ( x4 )
g (f (x)) = (log3 x) 4
Note: f g ≠ g f
32 33
Example Exercise
o Let f and g be functions from the positive
integers to the positive integers defined by the
equations, f (n) = n2 , g(n) = 2n
o Find the compositions
a) f f
b) g g
c) f g
d) g f
34 35
Recursive Algorithms Example
A recursive procedure is a procedure that Factorial problem
invokes itself. o If n ≥1,
A recursive algorithm is an algorithm that n! = n (n -1) => 2x1
contains a recursive procedure. and 0! = 1
Recursion is a powerful, elegant and natural o Notice that, if n ≥ 2, n factorial can be
way to solve a large class of problems. written as,
n! = n(n -1)(n -2) => 2x1x0
= n(n-1)!
36 37
6
10/20/2016
Example Recursive Algorithm for Factorial
38 39
Example
Recursive algorithm for Fibonacci Sequence :
for
40 41
Example Example- Solution
42 43