Topic4 Functions
Topic4 Functions
Topic 4: Functions
Exploring the fundamental concepts of mathematical functions in computer science
f :A → B f(x) = y
Domain & Range Mapping Composition Inverse
Input & Output sets One-to-one relation f∘g function Reverse mapping
Learning Objectives
f(1) = a, f(2) = a,
f(3) = c, f(4) = c.
Figure 5.1: Arrow diagram representing
relation f from A to B
Key Function Properties
Let us note the following crucial rules that define a valid function:
DEFINITION 5.1.1 Let A and B be nonempty sets and f be a relation from A into
B.
(ii) for all (a, b), (a', b') ∈ f, a = a' implies b = b'. In this case, we say that f is well defined or
single valued.
If (a, b) ∈ f (i.e., f(a) = b), then b is called the image of a under f, and a is called a preimage of b. We also say that a is
mapped to b.
Verification Conditions
The set A is referred to as the domain of the function and the set B is called the codomain, or
target, of f.
is a subset of the codomain B. The set f(A) is called the range of the function f, or the image of
the set A under the function f, denoted by Im(f) or I(f).
Examples of Finding Range
ℤ ℤ
Im(f) = {f(m) | m ∈ } = {2m + 1 | m ∈ } = set of all odd integers.
A B
f Every function is a relation.
1 Therefore, functions on finite sets can
a be described by arrow diagrams. In
2 the case of functions, the arrow
diagram may be drawn slightly
3 b differently.
If f : A → B is a function from a finite set
A into a finite set B, then in the arrow
4 c diagram, the elements of A are
enclosed in ellipses rather than
individual boxes.
To determine from its arrow diagram whether a relation f from a set A into a set B
is a function, two things are checked:
Check to see that there is only one arrow from each element of A to an
2) element of B.
This would ensure that f is well defined.
Valid Function Example
A f B
Let A = {1,2,3,4} and B = {a,b,c,d}. The diagram
represents relation f.
1 a
There is an arrow originating from each
2 b element of A.
D(f) = A
4 d
The image of g includes all elements of
B:
Im(g) = {a, b, c, d} = B
FIGURE 5.7 Arrow diagram of g
Non-Function: Not Well-Defined
A B
h Every element of A has some image in B;
therefore, D(h) = A.
1 a
However, element 1 has two images in B;
2 b i.e., there are two arrows originating from
1, one going to a and another going to b.
3 c
So h is not well defined.
If the domain and the range of a function are numbers, then the
function is typically defined by means of an algebraic formula.
DEFINITION 5.1.3
A function f : A → A is said to be the identity function if f(x) = x for all x ∈ A. This
function is usually denoted by iA.
DEFINITION 5.1.4
A function f : A → B is said to be a constant function if there exists b ∈ B such that
f(x) = b for all x ∈ A. That is, all elements of A are mapped to only one element of B.
Types of Functions: Injective, Surjective,
Bijective
DEFINITION 5.1.5 ▶ Let A and B be sets and f: A → B. Then:
(i) f is called one-one (or injective or injection) if for all a₁, a₂ ∈ A,
a₁ ≠ a₂ ⇒ f(a₁) ≠ f(a₂)
(i.e., images of distinct elements of the domain are distinct)
(ii) f is called onto B (or surjective or surjection) if for every b ∈ B there exists at least one a ∈ A such
that f(a) = b, i.e.,
Im(f) = B
(iii) f is called one-to-one correspondence (or bijective or bijection) if f is both one-one and onto.
Example: Bijective Function
Example 5.1.8
Let A = {1, 2, 3, 4} and B = {a, b, c, d}. Let f : A → B be a
function as shown.
A B
f
1 a The arrows from a distinct element of A go to a distinct
element of B. Every element of B has at most one arrow
coming to it.
2 b
If a₁, a₂ ∈ A and a₁ = a₂, then f(a₁) = f(a₂). Hence, f is
one-one.
3 c
Example 5.1.10
A B Let A = {1,2,3,4} and B = {a, b, c, d, e}
f
1 a
f : 1 → a, 2 → a, 3 → a, 4 → a
b
2 For this function, the images of distinct
c elements of the domain are not distinct. For
3 example:
d 1 ≠ 2, but f(1) = a = f(2)
4
e
Im(f) = {a} ≠ B
Hence, f is neither one-one nor onto
B.
FIGURE 5.11 Arrow diagram of f
Example: One-One But Not Onto
A B
f Let A = {1,2,3,4} and B = {a,b,c,d,e}.
a The function mappings are:
1 f: 1 → a, 2 → b, 3 → d, 4 → e
b
2 For this function, the images of distinct
c elements of the domain are distinct.
Thus, f is one-one.
3
d In this function, for the element c of B
4 (the codomain), there is no element x in
e the domain such that f(x) = c; i.e., c has
no preimage.
DEFINITION 5.1.6
Let f : A → B and g : B → C be functions. The composition of f and g, written g ∘ f, is the
function from A to C defined as:
(g ∘ f)(a) = g(f(a)), for all a ∈ A.
A B C
g∘f
f g
a f(a) g(f(a))
FIGURE 5.14 Arrow diagram of the functions f and g FIGURE 5.15 Arrow diagram of h = g ∘ f
Let A = {1,2,3,4}, B = {a,b,c,d,e}, and C = {7,8,9}. Consider the functions f : A → B, g : B → C defined by the arrow diagrams in Figure
5.14. The arrow diagram in Figure 5.15 describes the resulting composition function h = g ∘ f : A → C.
Composition with Identity
Theorem 5.1.1 :
Let f : A → B be a function from a set A into a set B. Consider the
identity functions iA : A → A and iB : B → B. Then
f ∘ iA = f = iB ∘ f .
Associativity of Composition
THEOREM 5.1.2
h ∘ (g ∘ f) = (h ∘ g) ∘ f ;
i.e., composition of functions is associative, provided the composition is defined.
Properties of Composition
Theorem 5.1.3
Suppose that f : A → B and g : B → C. The following assertions hold:
(i) If both f and g are one-one, then g ∘ f is also one-one.
(ii) If f is onto B and g is onto C, then g ∘ f is also onto C.
(iii) If both f and g are one-to-one correspondences (bijective), then g ∘ f is also a one-to-
one correspondence.
Theorem 5.1.4
Let A be a finite set and f : A → A be a function.
If f is one-one, then f is onto A and hence a one-to-one correspondence (bijective).
Special Functions and Cardinality
Let A = {1, 2, 3, 4, 5}, B = {a, b, c, d}, and f : A → B be defined by:
f(1) = a, f(2) = a, f(3) = b, f(4) = c, f(5) = d.
(a) Function f is onto B but not one-one (b) f⁻¹ is not a function (a maps to 1 and 2)
THEOREM 5.2.1
Corollary 5.2.1
Let f : A → B be a one-one and onto (bijective) function. Then f ⁻¹ : B → A is a one-one and onto
function. Moreover, f ⁻¹ ∘ f = iA and f ∘ f ⁻¹ = iB.
Theorem 5.2.2
Let f : A → B be a function such that f is one-one and onto B (bijective).
(i) If there exists a function g : B → A such that g ∘ f = iA, then g = f ⁻¹.
(ii) If there exists a function h : B → A such that f ∘ h = iB, then h = f ⁻¹.
Theorem 5.2.3
The inverse of a function, if it exists, is unique.
Left and Right Invertible Functions
DEFINITION 5.2.1 Let f : A → B be a function from the set A into the set B.
g ∘ f = i_A f ∘ h = i_B
A B A B A B
f g h f
a a b b
f(a) h(b)
Inverse Relation Detailed Analysis
2. Well-defined (Uniqueness):
Notice that the element a of B has two distinct
images, 1 and 2, under f⁻¹.
This violates the second condition.
Hence, f⁻¹ is not a function.
Inverse Function Theorem & Corollary
Theorem 5.2.1
Let f : A → B be a function. The inverse relation f⁻¹ ⊆ B × A is a function from B into A if
and only if f is both one-one and onto B.
Corollary 5.2.1
Let f : A → B be a one-one and onto function. Then f⁻¹ : B → A is a one-one and onto
function. Moreover,
f⁻¹ ∘ f = i A and f ∘ f⁻¹ = i B
Uniqueness of Inverse Functions
Theorem 5.2.2
Let f : A → B be a function such that f is one-one and onto B.
(i) If there exists a function g : B → A such that g ∘ f = iA, then g = f⁻¹.
(ii) If there exists a function h : B → A such that f ∘ h = iB, then h = f⁻¹.
Theorem 5.2.3
The inverse of a function, if it exists, is UNIQUE .
Left and Right Invertible Functions
DEFINITION 5.2.1 Let f : A → B be a function from the set A into the set B.
g ∘ f = iA f ∘ h = iB
Moreover, if such a function g exists, then g Moreover, if such a function h exists, then h
is called a left inverse of f. is called a right inverse of f.
Restriction of a Function
DEFINITION 5.2.2
Let f : A → B and ∅ ≠ A' ⊆ A. The restriction of f to A', written f|A', is defined to be:
Theorem 5.2.4
Let f : A → B be a function and C be a nonempty subset of A. Then the
restriction of f to C is UNIQUE.
Extension of a Function
DEFINITION 5.2.3
Let f : A → B and A ⊆ A'. A function g : A' → B is called an extension of f to A' if g|A = f.
EXAMPLE 5.2.4
Suppose A = { a ∈ ℝ | a > 0 }. Let f : A → ℝ be given by f(a) = 1 for all a ∈ A.
Theorem 5.2.5
Let X and Y be nonempty sets and f : X → Y be a function. Then f is one-one if and only if
f(A ∩ B) = f(A) ∩ f(B)
for all nonempty subsets A and B of X.
Floor Function
DEFINITION 5.2.4
For any real number x, the floor of x, written ⌊ x⌋, is the greatest integer less than or equal to
x.
EXAMPLE 5.2.6
Let x = 4.15. Here 4 is the greatest integer that does Let x = 3/4 = 0.75. Here 0 is the greatest integer that
not exceed 4.15. does not exceed 3/4.
Hence, ⌊4.15⌋ = 4 Hence, ⌊3/4⌋ = 0
Consider x = 48.0. The largest integer that does not Now consider x = -3.8. Observe that the largest
exceed 48.0 is 48. integer that does not exceed x is -4.
Thus, ⌊48.0⌋ = 48 Thus, ⌊-3.8⌋ = -4
Floor Function: Existence Proof
and
x − 1 < m < x.
Multiply the second inequality by −1, to get −(x − 1) > −m > −x or:
Thus, there exists only one integer n such that x − 1 < n < x. From this it follows that ⌊ x⌋ is the
unique integer satisfying x−1< x x⌊ ⌋≤ . (5.3)
Ceiling Function & Set Cardinality
EXAMPLE 5.2.9
Because f : ℕ → ℤ given by:
f(n) = { n/2-(n-1)/2
if n is even,
if n is odd
Figure 5.18 gives a graphic representation of f, showing a spiral pattern covering all integers.
Countable Sets Example
EXAMPLE 5.2.10
The set S = {n ∈ ℕ | n ≥ 3} is countable. Define the function f : ℕ → S by f(n) = n + 2 for all n
∈ ℕ. Then f is one-one and onto S (see Figure 5.19). Hence, S is countable.
Countable Sets Theorem & Uncountable Sets
Theorem 5.2.8
DEFINITION 5.2.10
An infinite sequence, or simply a sequence, on a nonempty set X is a function from the set of
positive integers ℕ, i.e., from the set {1, 2, ...} into X.
Let f be a sequence on a set X. Then f is a function from ℕ into X. Typically, we use the subscript
notation an (or xn, cn, sn) to denote the image f(n) of n in X.
Suppose f is a sequence on a set X given by f(n) = an. We generally represent f by listing its images at the
integers 1, 2, 3, ... in the form:
f: a1, a2, ..., an, ... or {a1, a2, ...} or briefly by {an}
Where an is the nth term of the sequence. (a1 is 1st term, a2 is 2nd term, etc.)
DEFINITION 5.3.2
Let a and d be real numbers. The sequence:
a, a + d, a + 2d, ..., a + (n - 1)d, a + nd, ...
is called an arithmetic progression (AP). We call a the first term, d the common difference, and a +
(n - 1)d the nth term.
EXAMPLE 5.3.7
Let {an}∞n=1 be an AP with first term a = 4 and common difference d = 5. Find the first four terms and the nth
term:
a1 = a = 4
a2 = a + d = 4 + 5 = 9
a3 = a + 2d = 4 + 2(5) = 14
a4 = a + 3d = 4 + 3(5) = 19
an = a + (n - 1)d = 4 + (n - 1)5 = 4 + 5(n - 1)
Geometric Progression (GP)
DEFINITION 5.3.3
Let a and r be real numbers. The sequence
a, ar, ar2, ..., arn-1, arn, ...
is called a geometric progression (GP). We call a the first term and r the common ratio of the sequence.
Furthermore, arn-1 is the nth term of the sequence.
EXAMPLE 5.3.8
Let {an}n=1∞ be a GP such that the first term is a = 3 and the common ratio is r = 1/2. Let us find the first four
terms and the nth term of this sequence.
a1 = a = 3
a2 = ar = 3 · (1/2) = 3/2
a3 = ar2 = 3 · (1/2)2 = 3/4
a4 = ar3 = 3 · (1/2)3 = 3/8
an = arn-1 = 3 / 2n-1
Summation & Product Notation
For any ordered pair (x, y) of elements x, y ∈ S, a binary ℤ is closed under + because if we add two
operation on S assigns a unique member of S. integers, we obtain an integer.
Because the image of S under * is a subset of S, we say that S is Thus, we say that ℕ is not closed under the
operation −.
closed under *.
Associative & Commutative Properties
x * (y * z) = (x * y) * z x*y=y*x
Mathematical System, Groupoid & Identity
DEFINITION 5.4.3 A nonempty set S together with a finite number of binary operations is called
▶
a mathematical system.
We denote a mathematical system by (S, *₁, *₂, *₃, . . . , *ₙ), where S is a nonempty set and *₁, *₂, *₃, .
. . , *ₙ are binary operations on S.
DEFINITION 5.4.4 ▶ A mathematical system (S, *) with only one binary operation is called
a groupoid.
e*x=x=x*e
Identity Element Uniqueness
Theorem 5.4.1:
An identity element (if it exists) of a mathematical system (S,
*) is unique.
e*x=x=x*e
Transformation Semigroup
TA = { f | f : A → A }
∘
Because composition of functions is a function, the operation (composition of functions), is a binary operation
on TA. By Theorem 5.1.2, ∘ is associative. Hence, TA is a semigroup with respect to the composition of functions.
This semigroup is called the transformation semigroup on A.
Theorem 5.4.2:
Let A be a nonempty set with more than two elements. The transformation
semigroup TA on A is a noncommutative monoid.
Idempotent Element & Band
Let A be an alphabet. Let A⁺ be the set of all nonempty strings on A. If u, v ∈ A⁺, then concatenation uv ∈ A⁺.
Thus, concatenation is a binary operation. By Theorem 5.3.23(ii), it is associative. Hence, A⁺ becomes a
semigroup with respect to concatenation. Called a free semigroup generated by A.
Base Elements Any non-empty set S Set of all non-empty strings A⁺ from alphabet A
Example (ℤ⁺, +) or (ℝ, ×) A = {a,b}. A⁺ = {a, b, aa, ab, ba, bb, aaa...}
Binary Operations: Free Monoid & Comparison
Let A* denote the set of all words including empty word λ. By Theorem 5.3.4(i), λs = s = sλ. Thus, A* is a
monoid with identity 1 = λ, called a free monoid generated by A.
If A has >1 element, A* is a noncommutative monoid.
Semigroup Set S with an associative binary Not required Depends on specific (ℤ, +), A⁺ (strings > 0 len)
operation (*) structure
General Monoid Semigroup that contains an identity Yes (e * x = x) Depends on specific (ℤ, +) with e=0
element e structure (TA, ∘) with e=iA
Free Monoid (A*) Set of all words from alphabet A, built Yes (Empty word λ) Noncommutative {0,1}* = {λ, 0, 1, 00, 01, 10, 11,
by concatenation (if |A| > 1, ab ≠ ba) ...}
Algebraic Structures: Concept Map
Semigroup Monoid
Associative binary operation Associative operation
No identity required + Add Identity Element Contains Identity Element (e)
Example: (ℤ⁺, +) or (2ℤ, ×) Example: (ℤ, +) with e=0
Free Semigroup A⁺ Free Monoid A*
Nonempty strings All words from alphabet A
Concat operation (assoc.) + Include empty string λ
Concat operation (assoc.)
No identity (λ excluded) Identity = empty word λ
TOPIC 4: FUNCTIONS - COMPREHENSIVE SUMMARY
7. Countable Sets
2. Function Types 12. Algebraic Structures
Cardinality, bijections with ℕ, countable sets (e.g., ℤ),
Injective (one-to-one), Surjective (onto), Bijective (one- • Groupoid: Mathematical system (S,*)
uncountable sets (e.g., ℝ), union theorems.
to-one correspondence), constant, identity. • Semigroup: Associative operation
• Monoid: Semigroup + Identity
• Band: Idempotent semigroup (a*a=a)
8. Sequences • Transformation Semigroup: TA with ∘
3. Composition Infinite sequences as functions (ℕ→X), Arithmetic
g∘f(x) = g(f(x)). Associative property, composition with Progression (AP), Geometric Progression (GP), Σ and
identity function, non-commutative generally. Π notation.