0% found this document useful (0 votes)
3 views

Wk6 Chapter 4 Mathematical Data Types (Part 2_Function) (1)

Chapter 4 of the document focuses on mathematical data types, specifically functions, their definitions, properties, and operations. It explains concepts such as injective, surjective, and bijective functions, along with examples to illustrate these properties. Additionally, it covers the representation of functions, the concept of inversion, and provides various examples to clarify the topics discussed.

Uploaded by

rino34rino45
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Wk6 Chapter 4 Mathematical Data Types (Part 2_Function) (1)

Chapter 4 of the document focuses on mathematical data types, specifically functions, their definitions, properties, and operations. It explains concepts such as injective, surjective, and bijective functions, along with examples to illustrate these properties. Additionally, it covers the representation of functions, the concept of inversion, and provides various examples to clarify the topics discussed.

Uploaded by

rino34rino45
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

CHAPTER 4

Mathematical Data Types


(Part 2)
CCC1113 Mathematics for Computer Science

Prepared by : Mdm. Nadiah Arsat


Index
▪Definition of functions ▪ Inversion
▪ Difference to relations
▪Composition
▪ Domain, codomain, image, pre-
▪Special functions
image, range
▪ Floor, ceiling, identity
▪Properties
▪ others
▪ Injective (one-to-one)

▪ Surjective (onto)

▪ Bijective (one-to-one and onto)


Definition of Functions
➢A function 𝑓 from a set 𝐴 to a set 𝐵 is an
assignment of exactly one element of 𝐵 to each 𝐴 𝐵
element of 𝐴
𝑓
➢Notation: 𝑓: 𝐴 → 𝐵 (𝑓 is a function from 𝐴 to 𝐵) 𝑎 𝑏 = 𝑓(𝑎)

➢𝑓 𝑎 = 𝑏, 𝑎 ∈ 𝐴, 𝑏 ∈ 𝐵 (𝑏 is the unique element


of 𝐵 assigned by the function 𝑓 to the element a
The function 𝑓 maps 𝐴 to 𝐵.
of 𝐴)
Definition of Functions
➢For 𝑓: 𝐴 → 𝐵
✓𝐴: domain of 𝑓
✓𝐵: codomain of 𝑓
𝐴 𝐵 Codomain
Domain
𝑓
➢For 𝑓(𝑎) = 𝑏 Range
✓𝑏: image of 𝑎 𝑎 𝑏 = 𝑓(𝑎)
✓𝑎: pre-image of 𝑏 𝑓 −1
Image

➢Range of 𝑓 : the set of all


images of elements of 𝐴/ 𝐵

➢𝑓: 𝐴 → 𝐵 maps 𝐴 to 𝐵
Example
➢Let 𝑅 be the relation with ordered pairs (Abdul, 22), (Brenda, 24), (Carla, 21), (Eddie,
24), and (Felicia, 22). Here each pair consists of a graduate student and this student’s
age. Specify a function determined by this relation.
Solution:
➢If 𝑓 is a function specified by 𝑅, then 𝑓 (Abdul ) = 22, 𝑓 (Brenda) = 24, 𝑓 (Carla) = 21,
𝑓 (Eddie) = 24, and 𝑓 (Felicia) = 22. [Here, 𝑓 (𝑥) is the age of 𝑥, where 𝑥 is a student.]
➢Domain : {Abdul, Brenda, Carla, Eddie, Felicia}.
➢Codomain contain all possible ages of students.
➢The range of the function we have specified is the set of different ages of these
students, which is the set {21, 22, 24}.
Other Ways to Represent 𝒇
x f(x)
Abdul
Abdul 22
21
Brenda
Brenda 24
Carla 22
Carla 21
Eddie 24
Eddie 24
Felicia
Felicia 22
Formula
➢The formula is used for the situations where the domain of a function is
large
➢E.g. : Let 𝑓 ∶ ℝ → ℝ, 𝑓 𝑥 = 2𝑥. Then,
▪𝑓 1 =2
▪𝑓 3 =6
▪ 𝑓 −3 = −6
▪…
➢ Domain?
➢ Codomain?
➢ Range?
Operations on Functions
➢Let 𝑓1 and 𝑓2 be functions from A to ℝ. Then, 𝑓1 +𝑓2 and 𝑓1 𝑓2 are also
functions from A to ℝ defined for all 𝑥 ∈ 𝐴
➢ Sum of 𝑓1 and 𝑓2 :
✓ 𝑓1 +𝑓2 𝑥 = 𝑓1 𝑥 +𝑓2 (𝑥)

➢Product of 𝑓1 and 𝑓2 :
✓(𝑓1 𝑓2 ) = 𝑓1 𝑥 𝑓2 (𝑥)

➢Example : Let 𝑓1 𝑥 = 3𝑥, 𝑓2 𝑥 = 𝑥 + 5


✓(𝑓1 + 𝑓2)(𝑥) = 𝑓1(𝑥) + 𝑓2(𝑥) = 3𝑥 + 𝑥 + 5 = 4𝑥 + 5
✓(𝑓1𝑓2)(𝑥) = 𝑓1(𝑥) 𝑓2(𝑥) = 3𝑥 (𝑥 + 5) = 3𝑥2 + 15𝑥
Image
➢Range of a function 𝑓: 𝐴 → 𝐵 is the set of all images of
elements 𝑎 ∈ 𝐴

➢A subset 𝑆 ⊆ 𝐴, the set of all images of elements 𝑠 ∈ 𝑆 is


called the image of 𝑆

➢Notation of image of 𝑆: 𝑓(𝑆)


✓𝑓(𝑆) = {𝑓(𝑠) | 𝑠 ∈ 𝑆}
Example
➢Given functions
✓𝑓 𝐿𝑖𝑛𝑑𝑎 = 𝑀𝑜𝑠𝑐𝑜𝑤
✓𝑓 𝑀𝑎𝑥 = 𝐵𝑜𝑠𝑡𝑜𝑛
✓𝑓 𝐾𝑎𝑡ℎ𝑦 = 𝐻𝑜𝑛𝑔 𝐾𝑜𝑛𝑔
✓𝑓 𝑃𝑒𝑡𝑒𝑟 = 𝐵𝑜𝑠𝑡𝑜𝑛
➢What is the image of 𝑆 = 𝐿𝑖𝑛𝑑𝑎, 𝑀𝑎𝑥 ?
▪ 𝑓 𝑆 = {𝑀𝑜𝑠𝑐𝑜𝑤, 𝐵𝑜𝑠𝑡𝑜𝑛}

➢What is the image of 𝑆 = 𝑀𝑎𝑥, 𝑃𝑒𝑡𝑒𝑟 ?


▪ 𝑓 𝑆 = {𝐵𝑜𝑠𝑡𝑜𝑛}
Properties of Functions
➢One-to-one (injective)

➢Onto (surjective)

➢One-to-one correspondence (bijective)

▪Inversion
One-to-One (injective)
➢A function 𝑓: 𝐴 → 𝐵 is said to be one-to-one (or injective), if
and only if

➢ ∀𝑥, 𝑦 ∈ 𝐴 (𝑓(𝑥) = 𝑓(𝑦) → 𝑥 = 𝑦)

➢i.e., 𝑓 is one-to-one if and only if it does not map two


distinct elements of 𝐴 onto the same element of 𝐵
One-to-One (injective)
- Examples
Example 1 Example 2
✓𝑓 𝐿𝑖𝑛𝑑𝑎 = 𝑀𝑜𝑠𝑐𝑜𝑤 ✓𝑔 𝐿𝑖𝑛𝑑𝑎 = 𝑀𝑜𝑠𝑐𝑜𝑤
✓𝑓 𝑀𝑎𝑥 = 𝐵𝑜𝑠𝑡𝑜𝑛 ✓𝑔 𝑀𝑎𝑥 = 𝐵𝑜𝑠𝑡𝑜𝑛
✓𝑓 𝐾𝑎𝑡ℎ𝑦 = 𝐻𝑜𝑛𝑔 𝐾𝑜𝑛𝑔 ✓𝑔 𝐾𝑎𝑡ℎ𝑦 = 𝐻𝑜𝑛𝑔 𝐾𝑜𝑛𝑔
✓𝑓 𝑃𝑒𝑡𝑒𝑟 = 𝐵𝑜𝑠𝑡𝑜𝑛 ✓𝑔 𝑃𝑒𝑡𝑒𝑟 = 𝑁𝑒𝑤 𝑌𝑜𝑟𝑘
➢Is this function 𝑓, one-to-one? ➢ Is this function 𝑔, one-to-one?
➢No, since Max and Peter are ➢Yes, each element is assigned a
mapped onto the same element of unique element of image.
the image.
One-to-One (injective)
– Examples
Example 3

➢Determine whether the function 𝑓 from {𝑎, 𝑏, 𝑐, 𝑑} to {1, 2, 3, 4, 5} with

𝑓 𝑎 = 4, 𝑓 𝑏 = 5, 𝑓 𝑐 = 1, and 𝑓 (𝑑) = 3 is one-to-one.

➢The function 𝑓 is one-to-one because 𝑓 takes on different values at

the four elements of its domain.


Onto (Surjective)
➢A function 𝑓: 𝐴 → 𝐵 is called onto, or surjective, if and only if

∀𝑏 ∈ 𝐵, ∃𝑎 ∈ 𝐴, 𝑓(𝑎) = 𝑏

➢i.e., 𝑓 is onto if and only if its range is its entire codomain

𝑎
1
𝑏

𝑐 2

𝑑 3
Onto (Surjective)
- Example
➢Let 𝑓 be the function from {𝑎, 𝑏, 𝑐, 𝑑} to {1, 2, 3} defined by

𝑓 (𝑎) = 3, 𝑓 (𝑏) = 2, 𝑓 (𝑐) = 1, and 𝑓 (𝑑) = 3. Is 𝑓 an onto function?

➢Because all three elements of the codomain are images of elements

in the domain, we see that 𝑓 is onto.

➢Note that if the codomain were {1, 2, 3, 4}, then 𝑓 would not be onto.
One-to-one correspondence
(bijective)
➢A function 𝑓: 𝐴 → 𝐵 is a one-to-one correspondence, or a bijection, if and only if
it is both one-to-one and onto

➢If 𝑓 is a bijection and 𝐴 and 𝐵 are finite sets, then |𝐴| = |𝐵|

➢Example : Let 𝑓 be the function from {𝑎, 𝑏, 𝑐, 𝑑} to {1, 2, 3, 4} with 𝑓(𝑎) = 4, 𝑓(𝑏) =
2, 𝑓(𝑐) = 1, and 𝑓 (𝑑) = 3. Is 𝑓 a bijection?

➢The function f is one-to-one and onto. It is one-to-one because no two values in the
domain are assigned the same function value. It is onto because all four elements of
the codomain are images of elements in the domain. Hence, f is a bijection.
Example 1
Linda Boston ➢Is 𝑓 injective?

Max New York ✓No

Kathy Hong Kong ➢Is 𝑓 surjective?


Peter Moscow ✓No

➢ Is 𝑓 bijective?
✓No
Example 2
Linda Boston ➢Is 𝑓 injective?
Max New York ✓No
Kathy Hong Kong
➢Is 𝑓 surjective?
Peter Moscow
✓Yes
Paul
➢ Is 𝑓 bijective?
✓No
Example 3
Linda Boston ➢Is 𝑓 injective?
Max New York ✓Yes
Kathy Hong Kong
➢Is 𝑓 surjective?
Peter Moscow
✓No
Kuala
Lumpur
➢ Is 𝑓 bijective?
✓No
Example 4
Linda Boston ➢Is 𝑓 injective?
Max New York ✓No. 𝑓 not a function
Kathy Hong Kong

Peter Moscow
Kuala
Lumpur
Example 5
Linda Boston ➢Is 𝑓 injective?
Max New York ✓Yes
Kathy Hong Kong
➢Is 𝑓 surjective?
Peter Moscow
✓Yes
Kuala
Helen
Lumpur
➢ Is 𝑓 bijective?
✓Yes
Inversion
➢A function 𝑓: 𝐴 → 𝐵 is a bijection then 𝑓 has an inverse function
𝑓 −1 : 𝐵 → 𝐴 such that𝑓 −1 𝑏 = 𝑎 if 𝑓(𝑎) = 𝑏

➢The function 𝑓 −1 is the inverse of function 𝑓.


Inversion (Example)
✓𝑓(𝐿𝑖𝑛𝑑𝑎) = 𝑀𝑜𝑠𝑐𝑜𝑤 ➢𝑓 −1 is given by :
✓𝑓 −1 (𝑀𝑜𝑠𝑐𝑜𝑤) = 𝐿𝑖𝑛𝑑𝑎
✓𝑓(𝑀𝑎𝑥) = 𝐵𝑜𝑠𝑡𝑜𝑛
✓𝑓 −1 (𝐵𝑜𝑠𝑡𝑜𝑛) = 𝑀𝑎𝑥
✓𝑓(𝐾𝑎𝑡ℎ𝑦) = 𝐻𝑜𝑛𝑔 𝐾𝑜𝑛𝑔 ✓𝑓 −1 (𝐻𝑜𝑛𝑔 𝐾𝑜𝑛𝑔) = 𝐾𝑎𝑡ℎ𝑦
✓𝑓 𝑃𝑒𝑡𝑒𝑟 = 𝐾𝑢𝑎𝑙𝑎 𝐿𝑢𝑚𝑝𝑢𝑟 ✓𝑓 −1 (𝐾𝑢𝑎𝑙𝑎 𝐿𝑢𝑚𝑝𝑢𝑟) = 𝑃𝑒𝑡𝑒𝑟
✓𝑓 −1 (𝑁𝑒𝑤 𝑌𝑜𝑟𝑘 = 𝐻𝑒𝑙𝑒𝑛
✓𝑓(𝐻𝑒𝑙𝑒𝑛𝑎) = 𝑁𝑒𝑤 𝑌𝑜𝑟𝑘

➢Clearly, 𝑓 is bijective. ➢Inversion is only possible for bijections


(= invertible functions)
Inversion (Example)
Linda Boston 𝑓
Max New York
𝑓 −1
Kathy Hong Kong

Peter Moscow
➢𝑓 −1 : 𝐶 → 𝑃 is not function, because
Kuala it is not defined for all elements of C
Helen
Lumpur and assigns two images to the pre-
image New York.
Summary of functions
and its properties
𝑋 𝑌 Codomain
Domain
𝑓
Range
𝑥 𝑓(𝑋)
𝑓 −1

➢Injective: 𝑓 is one-to-one
➢Surjective (onto) : Range = Co-domain
➢Bijective: 𝑓 is one-to-one and Onto
Composition
➢The composition of two functions 𝑔: 𝐴 → 𝐵 and
𝑓: 𝐵 → 𝐶, denoted by 𝑓 ∘ 𝑔, is defined by
(𝑓 ∘ 𝑔)(𝑎) = 𝑓(𝑔(𝑎))
➢First, function 𝑔 is applied to element 𝑎 ∈ 𝐴,
mapping it onto an element of 𝐵
➢Second, function 𝑓 is applied to this element
of 𝐵, mapping it onto an element of 𝐶
➢Therefore, the composite function maps from The composition of the functions 𝒇 and 𝒈
𝐴 to 𝐶
Composition (Example)

➢𝑓: ℝ → ℝ, 𝑓(𝑥) = 7𝑥 – 4

➢𝑔: ℝ → ℝ, 𝑔 𝑥 = 3𝑥

➢ 𝑓∘𝑔 𝑥 =𝑓 𝑔 𝑥 = 𝑓 3𝑥 = 7(3𝑥) – 4 = 21𝑥 – 4

➢ 𝑓∘𝑔 5 =𝑓 𝑔 5 =𝑓 3 5 = 𝑓 15 = 7 15 − 4 = 105 – 4 = 101


Composition of a Function
and its Inverse
➢ 𝑓 −1 𝑓 𝑥 = 𝑓 −1 𝑓 𝑥 =𝑥

➢The composition of a function and its inverse is the


identity function
Graphs
➢The graph of a function 𝑓: 𝐴 → 𝐵 is the set of ordered pairs
𝑎, 𝑏 𝑎 ∈ 𝐴 𝑎𝑛𝑑 𝑓(𝑎) = 𝑏}
➢The graph is a subset of 𝐴 × 𝐵 that can be used to visualize 𝑓 in
a two-dimensional coordinate system
➢Graph as relations
Graphs (Example)
➢Display the graph of the function
𝑓(𝑥) = 𝑥 2 from the set of integers to
the set of integers.
➢The graph of 𝑓 is the set of ordered
pairs of the form (𝑥, 𝑓(𝑥)) = (𝑥, 𝑥 2 ),
where 𝑥 is an integer.

The graph of 𝒇(𝒙) = 𝒙𝟐 from ℤ to ℤ


Floor and Ceiling Functions
➢Both map the real numbers onto integers (ℝ → ℤ)
➢The floor function assigns to 𝑟 ∈ ℝ the largest 𝑧 ∈ ℤ with 𝑧 ≤
𝑟, denoted by 𝑟
✓E.g.: 2.3 = 2, 2 = 2, 0.5 = 0, −3.5 = −4
➢The ceiling function assigns to 𝑟 ∈ ℝ the smallest 𝑧 ∈ ℤ with 𝑧 ≥
𝑟, denoted by 𝑟
✓E.g.: 2.3 = 3, 2 = 2, 0.5 = 1, −3.5 = −3
Other Functions for Computer Science
➢Mod-n function
➢Polynomial function
➢Base 2 exponential function
➢Logarithmic function
➢Characteristic function
➢Boolean function
➢Hashing function: h(n) = n (mod b)

You might also like