You are on page 1of 59

Ch3.

Functions,
Sequences, and Relations

School of Electronics Engineering


Prof. Jeongsik Choi
Contents
3.1 Functions

3.2 Sequences and Strings

3.3 Relations

3.4 Equivalence Relations

3.5 Matrices of Relations

Prof. Jeongsik Choi 2


Functions
Example
Credit card number: 4690 3582 1375 4657

Lunn Algorithm (By Hans Peter Luhn)


✓ Use last digit to verify card number

✓ Double every other digit and add all the digits


(if there is two-digit numbers add each digit)

✓ Verify card number using final output

Prof. Jeongsik Choi 3


Functions
Definition 3.1.1
A function from a set 𝑋 to a set 𝑌 is a subset of 𝑋 × 𝑌 such that
If 𝑥 ∈ 𝑋, there is exactly one 𝑦 ∈ 𝑌 with 𝑥, 𝑦 ∈ 𝑓

Also written as 𝑓: 𝑋 → 𝑌

𝑋 is called the domain, 𝑌 is called the codomain of f

Range of function 𝑓 is the set 𝑦 𝑥, 𝑦 ∈ 𝑓

Prof. Jeongsik Choi 4


Functions
Example 3.1.3
The set 𝑓 = 1, 𝑎 , 2, 𝑏 , 3, 𝑐 is a function from 𝑋 = 1, 2, 3 to
𝑌 = {𝑎, 𝑏, 𝑐}

Example 3.1.4
The set 𝑓 = 1, 𝑎 , 2, 𝑏 , 3, 𝑐 is not a function from 𝑋 = {1, 2, 3, 4} to
𝑌 = 𝑎, 𝑏, 𝑐

Prof. Jeongsik Choi 5


Functions
Example 3.1.5
The set 𝑓 = 1, 𝑎 , 2, 𝑏 , 3, 𝑐 , (1, 𝑏) is not a function from 𝑋 = 1, 2, 3
to 𝑌 = {𝑎, 𝑏, 𝑐}

Prof. Jeongsik Choi 6


Functions
Example 3.1.8
Let 𝑓 be the function defined by the rule 𝑓 𝑥 = 𝑥 2

𝑓= 𝑥, 𝑥 2 𝑥 is a real number}

Prof. Jeongsik Choi 7


Functions
Graph of a function
𝑓: subset of 𝐑 → subset of 𝐑 is visualized by plotting points in plane

Examples
✓ 𝑓 𝑥 = 𝑥 2 with domain 𝑹
✓ 𝑓 = { 0, 0 , 1, 1 , 2, 2 , 3, 0 , 1, 3 }

Prof. Jeongsik Choi 8


Functions
Definition 3.1.11
For an integer 𝑥 and positive integer 𝑦 is a positive integer, modulo
operation is defined as the remainder when 𝑥 is divided by 𝑦

Examples
✓ 6 mod 2 = 0
✓ 5 mod 1 = 1
✓ 8 mod 12 = 8
✓ 199673 mod 2 = 1

Prof. Jeongsik Choi 9


Functions
Example 3.1.14
What day of the week will it be 365 days from Wednesday?

Prof. Jeongsik Choi 10


Functions
Example 3.1.15
(Hash function) store number 𝑛 to memory with index ℎ 𝑛 =
𝑛 mod 11

Prof. Jeongsik Choi 11


Functions
Definition 3.1.17
Floor of 𝑥, 𝑥 is the greatest integer less than or equal to 𝑥
Ceiling of 𝑥, 𝑥 is the least integer greater than or equal to 𝑥

Examples
✓ 8.3 = 8
✓ −0.6 = −1
✓ 9.2 = 10
✓ −11.3 = −11

Prof. Jeongsik Choi 12


Functions
Definition 3.1.22
A function 𝑓: 𝑋 → 𝑌 is said to be one-to-one (injective)
if for ∀𝑥1 , 𝑥2 ∈ 𝑋, if 𝑓 𝑥1 = 𝑓(𝑥2 ) then 𝑥1 = 𝑥2

Examples
✓𝑓 = 1, 𝑏 , 3, 𝑎 , 2, 𝑐 from 𝑋 = {1, 2, 3} and 𝑌 = {𝑎, 𝑏, 𝑐, 𝑑}

✓𝑓 = 1, 𝑎 , 2, 𝑏 , 3, 𝑐 from 𝑋 = {1, 2, 3} and 𝑌 = {𝑎, 𝑏, 𝑐, 𝑑}

Prof. Jeongsik Choi 13


Functions
Example 3.1.27
Prove that 𝑓 𝑛 = 2𝑛 + 1 from 𝐍 to 𝐍 is one-to-one

Prof. Jeongsik Choi 14


Functions
Example 3.1.28
Prove that 𝑓 𝑛 = 2𝑛 − 𝑛2 from 𝐍 to 𝐙 it not one-to-one

Prof. Jeongsik Choi 15


Functions
Definition 3.1.29
A function 𝑓: 𝑋 → 𝑌 is said to be onto 𝑌 (surjective)
if for ∀𝑦 ∈ 𝑌, ∃𝑥 ∈ 𝑋 such that 𝑓 𝑥 = 𝑦

Examples
✓𝑓 = 1, 𝑏 , 2, 𝑐 , 3, 𝑏 from 𝑋 = {1, 2, 3} and 𝑌 = {𝑎, 𝑏, 𝑐}

✓𝑓 = 1, 𝑏 , 3, 𝑎 , 2, 𝑐 from 𝑋 = {1, 2, 3} and 𝑌 = {𝑎, 𝑏, 𝑐, 𝑑}

Prof. Jeongsik Choi 16


Functions
Example 3.1.33
Prove that 𝑓 𝑥 = 1/𝑥 2 from the set of non-zero real numbers to the
set of positive real numbers is onto 𝑌

Prof. Jeongsik Choi 17


Functions
Example 3.1.34
Prove that 𝑓 𝑛 = 2𝑛 − 1 from 𝐍 to 𝐍 is not onto 𝑌

Prof. Jeongsik Choi 18


Functions
Definition 3.1.15
A function that is both one-to-one and onto is called a bijection

Properties:
✓ If 𝑓: 𝑋 → 𝑌 is a bijection and 𝑋, 𝑌 are finite, then, 𝑋 = |𝑌|

✓ For a bijection 𝑓: 𝑋 → 𝑌, 𝑦, 𝑥 𝑥, 𝑦 ∈ 𝑓} is a function 𝑓 −1 : 𝑌 → 𝑋

Prof. Jeongsik Choi 19


Functions
Definition 3.1.41
For 𝑔: 𝑋 → 𝑌 and 𝑓: 𝑌 → 𝑍, the composition of 𝑓 with 𝑔 is defined as

𝑓 ∘ 𝑔 𝑥 = 𝑓(𝑔 𝑥 ) from 𝑋 to 𝑍

Examples
✓ 𝑔 = { 1, 𝑎 , 2, 𝑏 , 3, 𝑐 } from 𝑋 = 1, 2, 3 to 𝑌 = {𝑎, 𝑏, 𝑐}, and
𝑓 = { 𝑎, 𝑦 , 𝑏, 𝑥 , 𝑐, 𝑧 } from 𝑌 to 𝑍 = {𝑥, 𝑦, 𝑧}

✓ 𝑓 𝑥 = log 3 𝑥 and 𝑔 𝑥 = 𝑥 4

Prof. Jeongsik Choi 20


Functions
Binary and unary operators
Binary operator
𝑓: 𝑋 × 𝑋 → 𝑋

Unary operator
𝑓: 𝑋 → 𝑋

Examples: ∨, ∧, ¬, →, ⟷

Prof. Jeongsik Choi 21


Sequences and Strings
Example
Blue Taxi Inc. charges $1 for the first mile and 50 cents for each
additional mile

Prof. Jeongsik Choi 22


Sequences and Strings
Definition 3.2.1
A sequence 𝑠 is a function whose domain 𝐷 is a subset of integers

Denoted as 𝑠𝑛 or 𝑆(𝑛), where 𝑛 is called the index

Types of sequences
✓ Finite sequences
✓ Infinite sequences

Prof. Jeongsik Choi 23


Sequences and Strings
Notation for sequences

𝑛=𝑖 : finite sequence from index 𝑖 to 𝑗 (𝑠𝑖 , 𝑠𝑖+1 , … , 𝑠𝑗 )


𝑗
𝑠𝑛

𝑛=𝑘 : infinite sequence from index 𝑘 to infinity (𝑠𝑘 , 𝑠𝑘+1 , 𝑠𝑘+2 , …)



𝑠𝑛

Examples
✓ 𝑢𝑛 = 𝑛2 − 1 for all 𝑛 ≥ 0

✓ 𝑢𝑛 𝑛=0

Prof. Jeongsik Choi 24


Sequences and Strings
Example 3.2.5
Define a sequence 𝑏 by the rule 𝑏𝑛 is the 𝑛-th letter in ‘digital’’

Example 3.2.6
1
𝑥 is the sequence defined by 𝑥𝑛 = , −1 ≤ 𝑛 ≤ 4
2𝑛

Prof. Jeongsik Choi 25


Sequences and Strings
Increasing/decreasing sequences
Sequence 𝑠 is increasing if for all 𝑖 < 𝑗, 𝑠𝑖 < 𝑠𝑗

Sequence 𝑠 is decreasing if for all 𝑖 < 𝑗, 𝑠𝑖 > 𝑠𝑗

Sequence 𝑠 is nonincreasing if for all 𝑖 < 𝑗, 𝑠𝑖 ≥ 𝑠𝑗

Sequence 𝑠 is nondecreasing if for all 𝑖 < 𝑗, 𝑠𝑖 ≤ 𝑠𝑗

Prof. Jeongsik Choi 26


Sequences and Strings
Definition 3.2.12
For a sequence 𝑠, a subsequence is obtained from 𝑠 by choosing
certain terms in the order in which they appear in 𝑠

Examples
✓ b, c is a subsequence of a, a, b, c, q
✓ 2, 4, 8, 16, …, 2𝑘 , … is a subsequence of 2, 4, 6, 8, 10, …, 2𝑛, …

Prof. Jeongsik Choi 27


Sequences and Strings
Definition 3.2.17
For a sequence 𝑎𝑖 𝑛
𝑖=𝑚 ,

Sum of the sequence is defined as


𝑛

෍ 𝑎𝑖 = 𝑎𝑚 + 𝑎𝑚+1 + ⋯ + 𝑎𝑛
𝑖=𝑚

Product of the sequence is defined as


𝑛

ෑ 𝑎𝑖 = 𝑎𝑚 ⋅ 𝑎𝑚+1 ⋅ … ⋅ 𝑎𝑛
𝑖=𝑚

Prof. Jeongsik Choi 28


Sequences and Strings
Example 3.2.20
Rewrite the sum σ𝑛𝑖=0 𝑖𝑟 𝑛−1 by replacing the index as 𝑖 = 𝑗 − 1

Prof. Jeongsik Choi 29


Sequences and Strings
Strings
A string over 𝑋 (𝑋 is a finite set) is a finite sequence of elements in 𝑋
✓ e.g., 𝑋 = 𝑎, 𝑏, 𝑐 , the sequence b, a, a, c represents string ‘baac’

Repetition in a string can be specified by superscripts


✓ e.g., ‘b3a5qf2’

Null string: string with no element (𝜆 =‘ ‘)


✓ 𝑋 ∗ : set of all strings over 𝑋
✓ 𝑋 + : set of non-null strings over 𝑋

Prof. Jeongsik Choi 30


Sequences and Strings
String operations
Length of 𝛼, denoted as 𝛼
✓ Number of elements in 𝛼

Concatenation of 𝛼 and 𝛽, denoted as 𝛼𝛽


✓ String consisting of 𝛼 followed by 𝛽

Substring of 𝛼
✓ String obtained by selecting some or all consecutive elements of 𝛼
✓ 𝛽 is substring of 𝛼 if ∃𝛾, 𝛿 with 𝛼 = 𝛾𝛽𝛿

Prof. Jeongsik Choi 31


Sequences and Strings
Example 3.2.31
Let 𝑋 = {𝑎, 𝑏}. For 𝛼 ∈ 𝑋 ∗ , 𝛼 𝑅 denote 𝛼 in reverse. Prove that a
function 𝑓: 𝑋 ∗ → 𝑋 ∗ defined as 𝑓 𝛼 = 𝛼 𝑅 is bijection.

Prof. Jeongsik Choi 32


Sequences and Strings
Example 3.2.32
Let 𝑋 = {𝑎, 𝑏}. Determine if a function 𝑓: 𝑋 ∗ × 𝑋 ∗ → 𝑋 ∗ defined as
𝑓 𝛼, 𝛽 = 𝛼𝛽 is one-to-one or onto 𝑋 ∗

Prof. Jeongsik Choi 33


Relations
Definition 3.3.1
A (binary) relation 𝑅 from a set 𝑋 to a set 𝑌 is a subset of the
Cartesian product 𝑋 × 𝑌.

If 𝑥, 𝑦 ∈ 𝑅, we write 𝑥𝑅𝑦 and say that 𝑥 is related to y

If 𝑋 = 𝑌, we call R a (binary) relation on 𝑋

Note that a function is special form of a relation

Prof. Jeongsik Choi 34


Relations
Example 3.3.2
Relation of students to courses

𝑋={Bill, Mary, Beth, Dave}, 𝑌={CompSci, Math, Art, History}

𝑅={(Bill, CompSci), (Mary, Math), (Bill, Art), (Beth, History), (Beth,


CompSci), (Dave, Math)}

Prof. Jeongsik Choi 35


Relations
Example 3.3.3
For 𝑋 = 2, 3, 4 , 𝑌 = {3, 4, 5, 6, 7}, define a relation 𝑅 from 𝑋 to 𝑌 by
𝑥, 𝑦 ∈ 𝑅 if 𝑥 divides 𝑦

Prof. Jeongsik Choi 36


Relations
Graph for relations
A directional graph is used to illustrate the relation on a set

Main graph components


✓ Vertices: dots (nodes) of the graph
✓ Edges: lines that connect the vertices (directional or bi-directional)

In directional graphs, vertices are connected in certain directions

Prof. Jeongsik Choi 37


Relations
Example 3.3.4
Let 𝑅 be the relation on 𝑋 = 1, 2, 3, 4 defined by 𝑥, 𝑦 ∈ 𝑅 if 𝑥 ≤ 𝑦

Example 3.3.5
The relation 𝑅 on 𝑋 = {𝑎, 𝑏, 𝑐, 𝑑} is 𝑅 = { 𝑎, 𝑎 , 𝑏, 𝑐 , 𝑐, 𝑏 , 𝑑, 𝑑 }

Prof. Jeongsik Choi 38


Relations
Definition 3.3.6
A relation 𝑅 on a set 𝑋 is reflexive if 𝑥, 𝑥 ∈ 𝑅 for ∀𝑥 ∈ 𝑋

Examples
✓ Relation 𝑅 on 𝑋 = 1, 2, 3, 4 defined by 𝑥, 𝑦 ∈ 𝑅 if 𝑥 ≤ 𝑦

✓ Relation 𝑅 = a, a , b, c , c, b , d, d on 𝑋 = {𝑎, 𝑏, 𝑐, 𝑑}

Prof. Jeongsik Choi 39


Relations
Definition 3.3.9
A relation 𝑅 on a set 𝑋 is symmetric if 𝑥, 𝑦 ∈ 𝑅, then 𝑦, 𝑥 ∈ 𝑅

Examples
✓ 𝑅 = { 𝑎, 𝑎 , 𝑏, 𝑐 , 𝑐, 𝑏 , 𝑑, 𝑑 } on 𝑋 = {𝑎, 𝑏, 𝑐, 𝑑}

✓ 𝑅 on 𝑋 = {1, 2, 3, 4} defined by 𝑥, 𝑦 ∈ 𝑅 if 𝑥 ≤ 𝑦

Prof. Jeongsik Choi 40


Relations
Definition 3.3.12
A relation 𝑅 on a set 𝑋 is antisymmetric
if 𝑥, 𝑦 ∈ 𝑅 and 𝑦, 𝑥 ∈ 𝑅, then 𝑥 = 𝑦
(or contrapositive) if 𝑥 ≠ 𝑦 then 𝑥, 𝑦 ∉ 𝑅 or 𝑦, 𝑥 ∉ 𝑅

Example
✓ 𝑅 on 𝑋 = {1, 2, 3, 4} defined by 𝑥, 𝑦 ∈ 𝑅 if 𝑥 ≤ 𝑦

Prof. Jeongsik Choi 41


Relations
Definition 3.3.17
A relation 𝑅 on a set 𝑋 is a transitive if for ∀𝑥, 𝑦, 𝑧 ∈ 𝑋, if 𝑥, 𝑦 ∈ 𝑅
and 𝑦, 𝑧 ∈ 𝑅, then 𝑥, 𝑧 ∈ 𝑅

Example
✓ 𝑅 on 𝑋 = 1, 2, 3, 4 defined by 𝑥, 𝑦 ∈ 𝑅 if 𝑥 ≤ 𝑦

Prof. Jeongsik Choi 42


Relations
Definition 3.3.20
A relation 𝑅 on a set 𝑋 is a partial order in case that 𝑅 is reflexive,
antisymmetric, and transitive

Examples
✓ 𝑅 on 𝐍, defined as 𝑥, 𝑦 ∈ 𝑅 if 𝑥 ≤ 𝑦

✓ 𝑅 on 𝐍, defined as 𝑥, 𝑦 ∈ 𝑅 if 𝑥 divides 𝑦

Prof. Jeongsik Choi 43


Relations
Properties of partial orders
If 𝑅 is a partial order on a set 𝑋, 𝑥 ≼ 𝑦 indicates that 𝑥, 𝑦 ∈ 𝑅

If 𝑥, 𝑦 ∈ 𝑋 and either 𝑥 ≼ 𝑦 or 𝑦 ≼ 𝑥, then 𝑥 and 𝑦 are comparable

If 𝑥, 𝑦 ∈ 𝑋 and 𝑥 ⋠ 𝑦 and 𝑦 ⋠ 𝑥, then 𝑥 and 𝑦 are incomparable

If every pair of 𝑋 is comparable, 𝑅 is called total order

Prof. Jeongsik Choi 44


Relations
Definition 3.3.23
Let 𝑅 be a relation from 𝑋 to 𝑌. The inverse of 𝑅 is the relation from
𝑌 to 𝑋 such as
𝑅 −1 = 𝑦, 𝑥 𝑥, 𝑦 ∈ 𝑅}

Example:
✓ 𝑋 = {2, 3, 4}, 𝑌 = {3, 4, 5, 6, 7}, and 𝑥, 𝑦 ∈ 𝑅 if 𝑥 divides 𝑦

Prof. Jeongsik Choi 45


Relations
Definition 3.3.25
For relation 𝑅1 from 𝑋 to 𝑌 and relation 𝑅2 from 𝑌 to 𝑍, the
composition of 𝑅1 , 𝑅2 is the relation from 𝑋 to 𝑍 defined by

𝑅1 ∘ 𝑅2 = 𝑥, 𝑧 𝑥, 𝑦 ∈ 𝑅1 and 𝑦, 𝑧 ∈ 𝑅2 for some 𝑦 ∈ 𝑌}

Prof. Jeongsik Choi 46


Relations
Example 3.3.26
𝑅1 = 1, 2 , 1, 6 , 2, 4 , 3, 4 , 3, 6 , 3, 8
𝑅2 = 2, 𝑢 , 4, 𝑠 , 4, 𝑡 , 6, 𝑡 , 8, 𝑡

Prof. Jeongsik Choi 47


Equivalence Relations
Theorem 3.4.1
For a partition 𝒮 of a set 𝑋, 𝑥𝑅𝑦 is defined to mean that for some
𝑆 ∈ 𝒮, both 𝑥, 𝑦 ∈ 𝑆. Then, 𝑅 is reflexive, symmetric, and transitive

Prof. Jeongsik Choi 48


Equivalence Relations
Example 3.4.2
Consider 𝒮 = 1, 3, 5 , 2, 6 , 4 of 𝑋 = {1, 2, 3, 4, 5, 6}

Prof. Jeongsik Choi 49


Equivalence Relations
Definition 3.4.3
A relation that is reflexive, symmetric, and transitive on a set 𝑋 is
called an equivalence relation on 𝑋

Example
✓ 𝑅 = { 1, 1 , 1, 3 , 1, 5 , 2, 2 , 2, 4 , 3, 1 , 3, 3 , 3, 5 ,
4, 2 , 4, 4 , 5, 1 , 5, 3 , (5, 5)}

Prof. Jeongsik Choi 50


Equivalence Relations
Example 3.4.6
Relation 𝑅 on 𝑋 = {1, 2, 3, 4} defined by 𝑥, 𝑦 ∈ 𝑅 if 𝑥 ≤ 𝑦

Example 3.4.7
𝑅= 𝑎, 𝑎 , 𝑏, 𝑐 , 𝑐, 𝑏 , 𝑑, 𝑑 on 𝑋 = {𝑎, 𝑏, 𝑐, 𝑑}

Prof. Jeongsik Choi 51


Equivalence Relations
Theorem 3.4.8
For an equivalence relation 𝑅 on a set 𝑋, 𝑎 = 𝑥 ∈ 𝑋 𝑥𝑅𝑎} is
defined for ∀𝑎 ∈ 𝑋.
Then, 𝒮 = 𝑎 𝑎 ∈ 𝑋} is a partition of 𝑋

Prof. Jeongsik Choi 52


Equivalence Relations
Definition 3.4.9
For an equivalence relation relation 𝑅 on 𝑋, the sets [𝑎] are called
the equivalence classes of 𝑋 given by the relation 𝑅

Example:
✓ 𝑅 = { 1, 1 , 1, 3 , 1, 5 , 3, 1 , 3, 3 , 3, 5 , 5, 1 , 5, 3 , 5, 5 ,
2, 2 , 2, 6 , 6, 2 , 6, 6 , (4, 4)}

Prof. Jeongsik Choi 53


Equivalence Relations
Example 3.4.14
For 𝑋 = {1, 2, … , 10}, define 𝑥𝑅𝑦 to mean that 3 divides 𝑥 − 𝑦

Prof. Jeongsik Choi 54


Equivalence Relations
Theorem 3.4.16
Let 𝑅 be an equivalence relation on a finite set 𝑋. If each equivalence
class has 𝑟 elements, there are 𝑋 /𝑟 equivalence classes

Prof. Jeongsik Choi 55


Matrices of Relations
Matrix can be used to represent relations
Consider a relation 𝑅 from 𝑋 to 𝑌
✓ Row/column of a matrix can be labeled as elements of 𝑋 and 𝑌,
respectively
✓ Entities are set as 1 if 𝑥𝑅𝑦 and 0 otherwise

Example: 𝑅 = { 1, 𝑏 , 1, 𝑑 , 2, 𝑐 , 3, 𝑐 , 3, 𝑏 , 4, 𝑎 }

Prof. Jeongsik Choi 56


Matrices of Relations
Example 3.5.5
Let 𝑅1 be the relation from 𝑋 = {1, 2, 3} to 𝑌 = {𝑎, 𝑏} defined by

𝑅1 = 1, 𝑎 , 2, 𝑏 , 3, 𝑎 , 3, 𝑏

and 𝑅2 be the relation from 𝑌 to 𝑍 = {𝑥, 𝑦, 𝑧}

𝑅2 = 𝑎, 𝑥 , 𝑎, 𝑦 , 𝑏, 𝑦 , 𝑏, 𝑧

Prof. Jeongsik Choi 57


Matrices of Relations
Theorem 3.5.6
𝑅1 : relation from 𝑋 to 𝑌 which matrix is 𝐴1
𝑅2 : relation from 𝑌 to 𝑍 which matrix is 𝐴2
Then, the matrix for the relation 𝑅1 ∘ 𝑅2 can be constructed by
replacing non-zero elements in 𝐴1 𝐴2 by 1

Prof. Jeongsik Choi 58


Matrices of Relations
Example 3.5.7
𝑅 = { 𝑎, 𝑎 , 𝑏, 𝑏 , 𝑐, 𝑐 , 𝑑, 𝑑 , 𝑎, 𝑐 , 𝑐, 𝑏 }

Prof. Jeongsik Choi 59

You might also like