Functions
Functions
Functions
Functions
Introduction
Example
Suppose that each student in a discrete mathematics class is assigned a
letter grade from the set {A, B, C, D, F}. And suppose that the grades are;
A for Adam, C for Ahmed, B for Hassan, A for Reema, and F for Saif.
Adam ● ● A
Ahmed ● ● B
Hassan ● ● C
Reema ● ● D
Saif ● ● F
Functions are also used to represent how long it takes a computer to solve
problems of a given size.
Recursive functions, which are functions defined in terms of themselves, are used
throughout computer science
Functions
DEFINITION
B
Functions
One-to-One and Onto Functions
Some functions never assign the same value to two different domain elements. These
functions are said to be one-to-one.
DEFINITION
a ● ● 1
b ● ● 2
c ● ● 3
d ● ● 4
● 5
Note that a function f is one-to-one if and only if f (a) ≠ f (b) whenever a ≠ b.
This way of expressing that f is one-to-one is obtained by taking the
contrapositive of the implication in the definition.
Example
Determine whether the function f (x) = x2 from the set of integers to the set of
integers is one-to-one.
DEFINITION
Because all three elements of the codomain are images of elements in the
domain, we see that f is onto. Note that if the codomain were {1, 2, 3, 4}, then
f would not be onto.
Example
Is the function f (x) = x + 1 from the set of integers to the set of integers onto?
This function is onto, because for every integer y there is an integer x such that
f (x) = y. To see this, note that f (x) = y if and only if x + 1 = y, which holds if
and only if x = y − 1.
Functions 144 1442 / Basic
2 / Structures: Sets, Functions,
Basic Structures: Sequences,
Sets, Functions, Sums,
Sequences, and and
Sums,
144 2 / Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
Matrices
Matrices
Example
(a) One-to-one,
(a) One-to-one, (b) (b)Onto, Onto, (c) One-to-one,
(c) One-to-one, (d) Neither one-to
(d) Neither one
(a)
May 13, 2011 One-to-one,
10:24 (b)
not ontonot onto Onto, (c)
not one-to-one One-to-one, (d)
and onto Neither one-to-one (e)
nor nor N
ontoon
2011 10:24 not one-to-one and onto
not onto not 1one-to-one
a 1 a and onto
a a nor
1 onto
1a a
1 a a 1 a 1
a a 1 1
a 1 a
2 b 2 b b b 2 2b b
2 b b 2 b 2
b b 2 2
b 2 b
3 c 3 c 3 c c c c
3 c 3 3c c
3
c c 3 3
ctions, c 3 c
uences,Sequences,
Sums, and Sums,
Matricesand Matrices 4 d 4 d d d 4 4 4d d 4
4 d d d
(c) (c)FIGURE
One-to-one, FIGURE FIGURE
5 (d)Examples
One-to-one, Neither (d)5ofNeither
5 one-to-oneExamples
Examples
Different of
NotDifferent
of(e)Different
Types
one-to-one aof Types Types
aof
Correspondences.
(e) Not
function of Correspondences.
Correspondences.
function
-one and onto and onto nor onto nor onto
a a 1 a 1 a 1 1 1 1
1 a Solution:
This
Solution: Solution: function This
Thisais function
onto,
function because is for
is onto, onto, because
every
because for for
integer yevery
every there
int
b b 2 b 2 bf (x) = y. 2fTo y.2=Tonote
f=(x)
(x)see this, Tothat
y.see see f2this,
this, (x) note
note =that that
y if
2 and
f (x) = y=ififyxand
f (x)
only if+and=onl
1onlyy,i
2 x = y − 1. x =b yx − = 1.y − 1.b
c c 3 c 3 c 3 3 3 3
3 c c
d d EXAMPLE
4 d 4EXAMPLE
15 dConsider415
EXAMPLE 15
Consider
the function 4 f the function
in Example 4 f in
11 Example
that4assigns 11
Consider the function f in Example 11 that assigns job jobs that
to assigns
workers
for every for for every
job every
there is job there
a worker is a worker
assigned this assigned
job. Thethisthis job.f Th
function isf
least
job there is a worker assigned job. The
least one job that hasoneno job that assigned
worker has no worker
it. assigned it.
least one job that has no worker assigned it.
Functions
One-to-One and Onto
DEFINITION
Example
Let f be the function from {a, b, c, d} to {1, 2, 3, 4} with f(a) = 4, f(b) = 2,
f(c) = 1, and f(d)=3. Is f a bijection?
DEFINITION
Let f be a one-to-one correspondence from the set A to the set B.
The inverse function of f is the function that assigns to an element
b belonging to B the unique element a in A such that f (a) = b. The
inverse function of f is denoted by f −1. Hence, f −1(b) = a when f
(a) = b.
f -1(a)
● ●
a = f -1(b) b = f(a)
f(a)
f(x)
f -1
A B
f
Functions
Example Laws of Log
Example Laws of Logic
Adam Khali
Let f be theExample
function from {a, b, c} to {1,2,3} such that f(a) = 2, f(b) = 3, and
Adam Khalid
f(c) = 1.let = {a, b, and
Is ffinvertible, c} ! if it{1,
is, 2, 3},isf (a)
what = 2, (f (b) = 3, f (c) = 1
its inverse?
findletf f 1= 1{a, b, c} ! {1, 2, 3}, f (a) = 2, (f (b) = 3, f (c) = 1
find f
The function
Solution f is invertible because it is a one-to-one correspondence.
The inverseSolution
function f −1 reverses the correspondence given by f , so
f 1 : {1, 2, 3} ! {a, b, c}, f 1 (1) = c, f 2 (2) = a, f 1 (3) =
f (1) = c,f 1f −1
−1
: (2)
{1, =2,a,
3}and f −1(3)
! {a, = b.f 1 (1) = c, f 2 (2) = a, f 1 (3) =
b, c},
b b
Functions
Example
Let f : Z → Z be such that f(x) = x + 1. Is f invertible, and if it is, what is its
inverse?
The function f has an inverse because it is a one-to-one correspondence. To
reverse the correspondence, suppose that y is the image of x, so that
y = x + 1. Then x = y − 1. This means that y − 1 is the unique element of Z
that is sent to y by f . Consequently, f −1(y) = y − 1.
Functions
Example
Let f be the function from R to R with f (x) = x2. Is f invertible, and if it is, what is
its inverse?
DEFINITION
Let g be a function from the set A to the set B and let f be a function
from the set B to the set C. The composition of the functions f and g,
denoted for all a ∈ A by f ◦ g, is defined by
(f ◦ g) (a) = f (g(a)).
Functions
Composite Functions
(f ◦ g) (a)
g(a) f (g (a))
● ● ●
a g (a) f (g (a))
g(x) f(x)
A B C
(f ◦ g)
Functions
Example
Let g be the function from {a, b, c} to itself such that g(a) = b,
g(b) = c, and g(c) = a. Let f be the function from the set {a, b, c} to
the set {1, 2, 3} such that f (a) = 3, f (b) = 2, and f (c) = 1. What is
the composition of f and g, and what is the composition of g and f ?
and
(g ◦ f )(x) = g (f (x)) = g (2x + 3) = 3 (2x + 3) + 2 = 6x + 11.
Functions
The Graphs of Functions
DEFINITION
Let f be a function from the set A to the set B. The graph of
the function f is the set of ordered pairs {(a, b) | a ∈ A and
f(a) = b}.
(–2,4)
(–1,1)
(–2, 4) (2, 4)
(–1, 1) (1, 1)
(0, 0)
DEFINITION
The floor function assigns to the real number x the largest integer
that is less than or equal to x. The value of the floor function at x
is denoted by ⌊x⌋.
The ceiling function assigns to the real number x the smallest
integer that is greater than or equal to x. The value of the ceiling
function at x is denoted by ⌈x⌉.
Functions
Example
Write the values of the floor and ceiling functions given below:
!!
== 0 ⌊3.1⌋
⌊3.1⌋== 3
""
!!
== 1 ⌈3.1⌉
⌈3.1⌉== 4
""
! !
− − = =1 ⌊7⌋
⌊7⌋ == 7
" "
! !
− −= 0 ⌈7⌉
⌈7⌉ = 7
" "
Functions
Example
Data stored on a computer disk or transmitted over a data network are
usually represented as a string of bytes. Each byte is made up of 8 bits.
How many bytes are required to encode 100 bits of data?