Week 6 - Functions
Week 6 - Functions
5 FUNCTIONS
The student’s grade in a course is a function of the student’s performance. Many computer programs
and subroutines are designed to calculate values of functions. Hence, the concept of function is
important in mathematics and computer science. In the previous module, we have discussed truth
tables which can be regarded as Boolean function. In this module, the focus will be on discrete sets and
the use of function in mathematics.
Objectives:
DISCRETE STRUCTURES 1 41
Functions
Introduction
In many instances, we assign to each element of a set a particular element of a second set
(which may be the same as the first).
For 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 Adams, C for Chou, B for
Goodfriend, D for Rodriguez, and F for Stevens.
This assignment is an example of a function. The concept of a function is extremely important in
mathematics and computer science.
For example, in discrete mathematics, functions are used in the definition of such discrete
structures as sequences and strings.
Functions are also used to represent how long it takes a computer to solve problems of a given
size. Many computer programs and subroutines are designed to calculate values of functions.
Recursive functions, which are functions defined in terms of themselves, are used throughout
computer science.
Function
A function f from a set A to a set B is an assignment of exactly one element of B to each element
of A.
if b is the unique element of B assigned by the function f to the element a of A.
We write f(a) = b
If f is a function from A to B,
we write f: AB
(note: Here, ““ has nothing to do with if… then)
Example:
DISCRETE STRUCTURES 1 42
Functions
f(John) = Singapore
f(Peter) = Philippines
f(Liza) = India
f(Don) = Malaysia
Then
f(John) = Singapore
f(Peter) = Philippines
f(Liza) = India
f(Don) = Malaysia
DISCRETE STRUCTURES 1 43
Functions
The definition of a function implies that the arrow diagram for a function f has the
following two properties:
2. No two elements of X has two arrows coming out of it that point to two different
elements of Y.
Example:
Let
Range of f
{2, 4}
inverse image of 2
{a, c}
inverse image of 4
{b}
inverse image of 1
DISCRETE STRUCTURES 1 44
Functions
This illustrates the fact that although each element of the domain of a function must have an
arrow pointing out from it, there can be elements of the co-domain to which no arrows point.
Note also that there are two arrows pointing to the 2—one coming from a and the other from c.
Example:
Let f be the function that assigns the last two bits of a bit string of length 2 or greater to that
string.
For example, f (11010) = 10. Then, the domain of f is the set of all bit strings of length 2 or
greater, and both the codomain and range are the set {00, 01, 10, 11}.
Let f : Z Z assign the square of an integer to this integer. Then, f (x) = x2, where the domain of
f is the set of all integers, the codomain of f is the set of all integers, and the range of f is the set
of all integers that are perfect squares, namely, {0, 1, 4, 9, . . . }.
Exercise
Which of the arrow diagrams define functions from X = {a, b, c} to Y = {1, 2, 3, 4}?
Example:
Let
f:RR
f(x) = 2x
DISCRETE STRUCTURES 1 45
Functions
f(1) = 2
f(3) = 6
f(-3) = -6
DISCRETE STRUCTURES 1 46
Functions
Example:
Let
Then
the sum and the product of f1 and f2 are also functions from A to R defined by:
Note that the functions f1 + f2 and f1f2 have been defined by specifying their values at x in terms
of the values of f1 and f2 at x.
Example:
f1(x) = 3x,
f2(x) = x + 5
Exercise
Let
We already know that the range of a function f:AB is the set of all images of elements aA.
If we only regard a subset S A, the set of all images of elements sS is called the image of S.
f(S) = {f(s) | s S}
DISCRETE STRUCTURES 1 47
Functions
Example:
f(John) = Singapore
f(Peter) = Philippines
f(Liza) = Singapore
f(Don) = Malaysia
Exercise
Let
A = {a, b, c, d, e}
B = {1, 2, 3, 4}
Find f(S) = ?
Types of functions
1. One-to-one
2. Onto
3. One-to-one correspondence
One-to-one
DISCRETE STRUCTURES 1 48
Functions
Example:
f(John) = Singapore
f(Peter) = Philippines
f(Liza) = Singapore
f(Don) = Malaysia
Is f One-to-one?
No, John and Liza are mapped onto the same element of the image.
g(John) = Singapore
g(Peter) = Philippines
g(Liza) = India
g(Don) = Malaysia
Is g One-to-one?
Exercise
Determine whether the function f from {a, b, c, d} to {1, 2, 3, 4, 5} with f(a)=4, f(b)=5, f(c)=1, and f(d)=3 is
one-to-one.
DISCRETE STRUCTURES 1 49
Functions
Onto
A function f:AB is called onto, or surjective, if, and only if, for every element bB there is
an element aA with f(a) = b.
In other words, f is onto if, and only if, its range is its entire codomain.
That is, f is onto if every element of its co-domain is the image of some element(s) of its
domain. Thus, co-domain of f = range of f
Using the arrow diagram, a function is onto if each element of the co-domain has an
arrow pointing to it from some element of the domain.
A function is not onto if at least one element in its co-domain does not have an arrow
pointing to it.
Exercise
Determine whether the function f from {a, b, c, d, e} to {1, 3, 4, 5} with f(a)=4, f(b)=5, f(c)=1, f(d)=3, and
f(e)=1 is onto.
DISCRETE STRUCTURES 1 50
Functions
One-to-one correspondence
A function f: AB is a one-to-one correspondence, or a bijection, if, and only if, it is both one-
to-one and onto.
Obviously, if f is a bijection and A and B are finite sets, then |A| = |B|.
Consider a function F: AB that is both one-to-one and onto. Given any element x in A,
there is a unique corresponding element b = F(a) in B (since F is a function).
Also given any element b in B , there is an element a in A such that F(a) = b (since F is
onto) and there is only one such a (since F is one-to-one).
Thus, a function that is one-to-one and onto sets up a pairing between the elements of
A and the elements of B that match.
Exercise
Determine whether the function f from {a, b, c, d} to {1, 3, 4, 5} with f(a)=4, f(b)=5, f(c)=1, and f(d)=3 is
one-to-one correspondence.
DISCRETE STRUCTURES 1 51
Functions
References:
1. Kenneth H. Rosen. Discrete Mathematics and Its Applications, 7th Edition. McGrawHill, 2012
2. Gary Weiss Damian Lyons, et al., Fundamentals of Discrete Structures, 2nd edition, Pearson
Learning Solutions, 2012.
3. Susanna S. Epp, Discrete Mathematics with Applications, Brooks Cole; 4th edition, 2011.
4. James L. Hein, Discrete Structures, Logic, and Computability, 3rd edition, Jones & Bartlett
Publishers, 3rd edition, 2009.
5. Kolman, B., Busby, R. C., Ross, S. C. Discrete Mathematical Structures, 6th Edition. Prentice Hall,
2008.
DISCRETE STRUCTURES 1 52