1. Functions and Sequences - 02 CSC1001 Discrete Mathematics 1
CHAPTER
ฟังก์ชนและลําดับ
ั
2 (Functions and Sequences)
1 Functions
1. Introduction to Functions
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, A for Rodriguez, and F for Stevens. This assignment of grades is illustrated in figure below.
Figure: Assignment of Grades in a Discrete Mathematics Class
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. Functions are sometimes also called mappings or transformations.
Definition 1
Let A and B be nonempty sets. A function f from A to B is an assignment of exactly one element of B to
each element of A. We write f(a) = b if b is the unique element of B assigned by the function f to the
element a of A. If f is a function from A to B, we write f : A → B.
Definition 2
If f is a function from A to B, we say that A is the domain of f and B is the codomain of f. If f(a) = b, we say
that b is the image of a and a is a preimage of b. The range, or image, of f is the set of all images of
elements of A. Also, if f is a function from A to B, we say that f maps A to B.
มหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี
2. 2 CSC1001 Discrete Mathematics 02 - Functions and Sequences
Example 1 (6 points) Function or not?
1. 2. 3.
1 1 1 1 1 1
2 2 2 2 2 2
3 3 3 3 3 3
4 5 4 5 4 5
4 4 4
4. 5. 6.
1 1 1 1 1 1
2 2 2 2 2 2
3 3 3 3 3 3
4 5 4 5 4 5
4 4 4
Example 2 (3 points) What are the domain, codomain, and range of the in the figure?
Solution: Let G be the function that assigns a grade to a student in our
discrete mathematics class. Note that G(Adams) = A, for instance. The
domain of G is the set {Adams, Chou, Goodfriend, Rodriguez, Stevens},
and the codomain is the set {A,B,C,D,F}. The range of G is the set
{A,B,C,F}, because each grade except D is assigned to some student.
Example 3 (3 points) What are the domain, codomain, and range of the function in the figure?
1 1
2 2
3 3
4 5
4
Example 4 (3 points) What are the domain, codomain, and range of the function in the figure?
1 1
2 2
3 3
4 5
4
Example 5 (3 points) What are the domain, codomain, and range of the function in the figure?
A 1
B 2
C 3
D 4
มหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี
3. Functions and Sequences - 02 CSC1001 Discrete Mathematics 3
Example 6 (3 points) 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. What are the domain, codomain, and range of this function?
Example 7 (3 points) Let f : Z → Z assign the square of an integer to this integer. Then, f(x) = x2, What are
the domain, codomain, and range of this function?
Example 8 (3 points) Let f : Z+ → Z+ assign to f(x) = 2x + 1, What are the domain, codomain, and range of
this function?
Example 9 (3 points) Let f : N → R assign to f(x) = x, What are the domain, codomain, and range of this
function?
Example 10 (3 points) What are the domain, codomain, and range of functions are specified in Java pro-
gramming (represented using method).
public static int floor(double real) {
//statements
}
มหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี
4. 4 CSC1001 Discrete Mathematics 02 - Functions and Sequences
2. Addition and Multiplication of Functions
Definition 3
Let f1 and f2 be functions from A to R. Then f1 + f2 and f1f2 are also functions from A to R defined by
(f1 + f2)(x) = f1(x) + f2(x) for all x ∈ A
(f1f2)(x) = f1(x)f2(x) for all x ∈ A
Example 11 (5 points) Let f1 and f2 be functions from R to R such that f1(x) = x2 and f2(x) = x - x2. What are
the functions f1 + f2 and f1f2?
Example 12 (5 points) Let f1 and f2 be functions from R to R such that f1(x) = x2 + 2x + 3 and f2(x) = x - 4.
What are the functions f1 + f2 and f1f2?
Example 13 (5 points) Let f1 and f2 be functions from R to R such that f1(x) = 9x - 5 and f2(x) = x + 2. What are
the functions f1 + f2 and f1f2?
Example 14 (5 points) Let f1 and f2 be functions from R to R such that f1(x) = x - 4 and f2(x) = x3 + 2x2.
What are the functions f1 + f2 and f1f2?
มหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี
5. Functions and Sequences - 02 CSC1001 Discrete Mathematics 5
3. One-to-One Functions
Some functions never assign the same value to two different domain elements. These functions are said to
be one-to-one function.
Definition 4
A function f is said to be one-to-one, or an injunction, if and only if f(a) = f(b) implies that a = b for all a and
b in the domain of f. A function is said to be injective if it is one-to-one.
Figure: An One-to-One Function
Example 15 (6 points) One-to-one function or not?
1. 2. 3.
1 1 1 1 1 1
2 2 2 2 2 2
3 3 3 3 3 3
4 5 4 5 4 5
4 4 4
4. 5. 6.
1 1 1 1 1 1
2 2 2 2 2 2
3 3 3 3 3 3
4 5 4 5 4 5
4 4 4
Example 16 (1 points) 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 or not?, why?
Example 17 (1 points) Determine whether the function f(x) = x2 from the set of integers to the set of integers is
one-to-one or not?, why?
มหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี
6. 6 CSC1001 Discrete Mathematics 02 - Functions and Sequences
Example 18 (1 points) Determine whether the function f(x) = x + 1 from the set of real numbers to itself is one-
to-one or not?, why?
Example 19 (1 points) Determine whether the function f(x) = 5x - 3 from the set of real numbers to itself is
one-to-one or not?, why?
4. Onto Functions
For some functions the range and the codomain are equal. That is, every member of the codomain is the
image of some element of the domain. Functions with this property are called onto functions.
Definition 5
A function f from A to B is called onto, or a surjection, if and only if for every element b ∈ B there is an
element a ∈ A with f(a) = b. A function f is called surjective if it is onto.
Figure: An Onto Function
Example 20 (6 points) Onto function or not?
1. 2. 3.
1 1 1 1 1 1
2 2 2 2 2 2
3 3 3 3 3 3
4 5 4 4 4
4
4. 5. 6.
1 1 1 1
2 1 2 2 2 2
3 2 3 3 3 3
4 4 4 4 5
5 4
มหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี
7. Functions and Sequences - 02 CSC1001 Discrete Mathematics 7
Example 21 (1 points) Let f be the function from {a, b, c, d} to {1, 2, 3} defined by f(a) = 3, f(b) = 2, f(c) = 1,
and f(d) = 3. Is f an onto function or not?, why?
Example 22 (1 points) Let f be the function from {a, b, c, d} to {1, 2, 3, 4} defined by f(a) = 2, f(b) = 1, f(c) = 1,
and f(d) = 4. Is f an onto function or not?, why?
Example 23 (1 points) Is the function f(x) = x2 from the set of integers to the set of integers onto or not?, why?
Example 24 (1 points) Is the function f(x) = x + 1 from Z → Z onto or not?, why?
Definition 6
The function f is a one-to-one correspondence, or a bijection, if it is both one-to-one and onto. We also say
that such a function is bijective.
Example 25 (5 points) One-to-one function or not? / Onto function or not?
1. 2. 3. 4. 5.
Example 26 (1 points) 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?
Example 27 (1 points) Let f be the function from {a, b, c, d} to {1, 2, 3} with f(a) = 1, f(b) = 2, f(c) = 1, and f(d)
= 3. Is f a bijection?
มหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี
8. 8 CSC1001 Discrete Mathematics 02 - Functions and Sequences
5. Inverse Functions
Definition 7
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.
Figure: The Function f-1 Is the Inverse of Function f
Example 28 (2 points) Let f be the function from {a, b, c} to {1, 2, 3} such that f(a) = 2, f(b) = 3, and f(c) = 1.
What is its inverse?
Example 29 (5 points) Let f : Z → Z be such that f(x) = x + 1. What is its inverse?
Example 30 (5 points) Let f : Z → Z be such that f(x) = 4x - 17. What is its inverse?
Example 31 (5 points) Let f : R → R be such that f(x) = x2 + 5. What is its inverse?
มหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี
9. Functions and Sequences - 02 CSC1001 Discrete Mathematics 9
6. Composite Functions
Definition 8
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 o g, is defined by (f o g)(a) = f(g(a))
Figure: The Composition of the Functions f and g
Example 32 (4 points) Let g be the function from the set {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 ?
Example 33 (10 points) Let f and g be the functions from the set of integers to the set of integers defined by
f(x) = 2x + 3 and g(x) = 3x + 2. What is the composition of f and g? What is the composition of g and f ?
Example 34 (10 points) Let f and g be the functions from the set of integers to the set of integers defined by
f(x) = x2 + 1 and g(x) = x - 3. What is the composition of f and g? What is the composition of g and f ?
มหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี
10. 10 CSC1001 Discrete Mathematics 02 - Functions and Sequences
Example 35 (10 points) Let f and g be the functions from the set of integers to the set of integers defined by
f(x) = 3x2 – 4x + 2 and g(x) = x + 2. What is the composition of f and g? What is the composition of g and f ?
7. Floor and Ceiling Functions
Definition 9
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 ⎤ .
Example 36 (10 points) Find some values of the floor and ceiling functions
⎢1⎥ ⎡1⎤
⎢2⎥ = …………………………………………….. ⎢2⎥ = ……………………………………………..
⎣ ⎦ ⎢ ⎥
⎢ 1⎥ ⎡ 1⎤
⎢− 2 ⎥ = …………………………………………….. ⎢− 2 ⎥ = ……………………………………………..
⎣ ⎦ ⎢ ⎥
⎣3.1⎦ = …………………………………………….. ⎡3.1⎤ = ……………………………………………..
⎣7⎦ = …………………………………………….. ⎡7⎤ = ……………………………………………..
⎣4.9⎦ = …………………………………………….. ⎡4.9⎤ = ……………………………………………..
⎣9.5⎦ = …………………………………………….. ⎡9.5⎤ = ……………………………………………..
มหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี
11. Functions and Sequences - 02 CSC1001 Discrete Mathematics 11
Example 37 (5 points) Data stored on a computer disk or transmitted over a data network are usually repre-
sented as a string of bytes. Each byte is made up of 8 bits. How many bytes are required to encode 100 bits
of data?
Example 38 (5 points) In asynchronous transfer mode (ATM) (a communications protocol used on backbone
networks) data are organized into cells of 53 bytes. How many ATM cells can be transmitted in 1 minute over
a connection that transmits data at the rate of 500 kilobits per second?
2 Sequences
1. Introduction to Sequences
A sequence is a discrete structure used to represent an ordered list of elements. For example, 1, 2, 3, 5,
8 is a sequence with five terms and 1, 3, 9, 27, 81 , . . . , 3n, . . . is an infinite sequence. They can be also
used to represent solutions to certain counting problems and they are also an important data structure in
computer science. We will often need to work with sums of terms of sequences in our study of discrete
mathematics.
Definition 1
A sequence is a function from a subset of the set of integers (usually either the set {0, 1, 2, . . .} or the set
{1, 2, 3, . . .}) to a set S. We use the notation an to denote the image of the integer n. We call an a term of
the sequence. We use the notation {an} to describe the sequence.
Example 1 (4 points) Can you show the list of terms of the sequence below, beginning with a1 to a5
1
1) an =
n
2) an = 2 n − 1
มหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี
12. 12 CSC1001 Discrete Mathematics 02 - Functions and Sequences
2. Geometric Progression and Arithmetic Progression
Definition 2
A geometric progression is a sequence of the form
a, ar, ar2, . . . , arn, . . .
where the initial term a and the common ratio r are real numbers.
Example 2 (8 points) Can you show the list of terms of the sequence below, beginning with a1 to a5
1) a n = (−1) n
2) an = 2 ⋅ 3n
n
⎛1⎞
3) an = 5 ⋅ ⎜ ⎟
⎝2⎠
(−1) n
4) an = −
2
Definition 3
An arithmetic progression is a sequence of the form
a, a + d, a + 2d, . . . , a + nd, . . .
where the initial term a and the common difference d are real numbers.
Example 3 (8 points) Can you show the list of terms of the sequence below, beginning with a1 to a5
1) a n = −1 + 4n
2) a n = 7 − 3n
1
3) an = 5 + n
2
1
4) an = − 2n
4
มหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี
13. Functions and Sequences - 02 CSC1001 Discrete Mathematics 13
3. Recurrence Relations
Definition 4
A recurrence relation for the sequence {an} is an equation that expresses an in terms of one or more of the
previous terms of the sequence, namely, a0, a1, . . . , an-1, for all integers n with n ≥ n0, where n0 is a
nonnegative integer. A sequence is called a solution of a recurrence relation if its terms satisfy the
recurrence relation. (A recurrence relation is said to recursively define a sequence.
Example 4 (2 points) Let {an} be a sequence that satisfies the recurrence relation an = an-1 + 3 for n = 1, 2, 3,
4, . . . , and suppose that a0 = 2. What are a1, a2, a3, a4, and a5?
Example 5 (2 points) Let {an} be a sequence that satisfies the recurrence relation an = an-1 + an-2 for n = 2, 3,
4, . . . , and suppose that a0 = 3 and a1 = 5. What are a1, a2, and a3?
Definition 5
The Fibonacci sequence, f0, f1, f2, . . . , is defined by the initial conditions f0 = 0, f1 = 1, and the recurrence
relation fn = fn-1 + fn-2 for n = 2, 3, 4, . . . .
Example 6 (2 points) Find the Fibonacci numbers f2, f3, f4, f5, and f6
f2 =
f3 =
f4 =
f5 =
f6 =
Example 7 (2 points) Suppose that {an} is the sequence of integers defined by an = n!, the value of the
factorial function at the integer n, where n = 1, 2, 3, . . .. Because n! = n(n - 1)(n - 2) . . .2・1 = n(n - 1)! = nan-1,
find the sequence of factorials a2 to a5 with the initial condition a1 = 1.
มหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี
14. 14 CSC1001 Discrete Mathematics 02 - Functions and Sequences
Example 8 (2 points) Find formulae for the sequences with the following first five terms 1, 1/2, 1/4, 1/8, 1/16
Example 9 (2 points) Find formulae for the sequences with the following first five terms 1, 3, 5, 7, 9
Example 10 (2 points) Find formulae for the sequences with the following first five terms 1, -1, 1, -1, 1.
Example 11 (2 points) Find formulae for the sequences with the following first five terms 1, 4, 9, 16, 25.
Example 12 (2 points) Find formulae for the sequences with the following first five terms 1, 7, 25, 79, 241.
Example 13 (2 points) Find formulae for the sequences with the following first five terms 5, 11, 17, 23, 29.
Example 14 (2 points) Find terms number 18 of a sequence if the first 10 terms are 1, 2, 2, 3, 3, 3, 4, 4, 4, 4?
Example 15 (2 points) Find terms number 15 of a sequence if the first 8 terms are 1, 3, 4, 7, 11, 18, 29, 47?
มหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี
15. Functions and Sequences - 02 CSC1001 Discrete Mathematics 15
4. Summations
Definition 6
The addition of the terms of a sequence is summation. We begin by describing the notation used to
express the sum of the terms am, am+1, . . . , an from the sequence {an}. We use the notation
n
∑a
i =m
i or ∑ m ≤i ≤ n
ai
(read as the sum from i = m to i = n of ai )
Example 16 (2 points) Use summation notation to express the sum of the first 100 terms of the sequence {ai},
where ai = 1/i for i = 1, 2, 3, . . . .
Example 17 (2 points) Use summation notation to express the sum of the first 500 terms of the sequence {ai},
where ai = 2i3 + 4i - 5 for i = 1, 2, 3, . . . .
5
Example 18 (2 points) What is the value of ∑ i 2 .
i =1
8
Example 19 (2 points) What is the value of ∑ (3k − 4) .
k =4
Definition 7
If a and r are real numbers and r ≠ 0, then
⎧(n + 1)a if r = 1
n
⎪
sn = ∑ ar = ⎨ ar n+1 − a
i
if r ≠ 1
i =0 ⎪
⎩ r −1
Sums of terms of geometric progressions called geometric series
มหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี
16. 16 CSC1001 Discrete Mathematics 02 - Functions and Sequences
Example 20 (2 points) Given an = 2 ⋅ 3n find s10
Example 21 (2 points) Given a n = −(1n ) find s10
Definition 8
Double summations arise in many contexts (as in the analysis of nested loops in computer programs). An
example of a double summation is
m n
∑∑ ij
i =1 j =1
4 3
Example 22 (4 points) Find the double summation of ∑∑ ij
i =1 j =1
4 3
Example 23 (4 points) Find the double summation of ∑∑ (i + j)
i =1 j =1
5. Summation Formulae
Summations Closed Form
ar n +1 − a
n
∑ ar
k =0
k
(r ≠ 0)
r −1
,r ≠ 1
n
n(n + 1)
∑k
k =1 2
n
n(n + 1)(2n + 1)
∑k
k =1
2
6
n 2 (n + 1) 2
n
∑k
k =1
3
4
มหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี
17. Functions and Sequences - 02 CSC1001 Discrete Mathematics 17
100
Example 24 (4 points) Find ∑ k 2
k =50
20
Example 25 (4 points) Find ∑ k 3
k =10
15
Example 26 (4 points) Find ∑ k
k =8
10 25
Example 27 (8 points) Find ∑ k 2 + ∑ k 2
k =5 k =15
มหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี