DISCRETE MATHEMATICS
LECTURE 5
FUNCTIONS
1
Function
Definition
• Let A and B be 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.
Function
• If f is a function from A to B, we write f : A B.
• Set A is called the domain of the function.
• Set B is called the codomain of the function.
• If f(a) = b, then b is the image of a and a is the pre-image of b.
Function
Definition of a function
f:R Z
f maps R to Z
Domain R Z Co-domain
f
f(4.3)
4.3 4
Pre-image of 4 Image of 4.3
Function
More functions
A pre-image The image
Domain Co-domain of 1 of “a”
Nusrat A “a” 1
Shadikul B “bb“ 2
Fatema C “cccc” 3
Z D “dd” 4
Harun F “e” 5
A class grade function A string length function
Function
Even more functions
Range
a 1 “a” 1
e 2 “bb“ 2
i 3 “cccc” 3
o 4 “dd” 4
u 5 “e” 5
Some function… Not a valid function!
One to One Function
One-to-one functions
Definition
A function is one-to-one if elements in the co-domain has a unique pre-
image in the domain.
a 1 a 1
e 2 e 2
i 3 i 3
o 4 o 4
5 5
A one-to-one function A function that is
not one-to-one
One to One Function
More on one-to-one
• Injective is synonymous with one-to-one
• A function is an injection if it is one-to-one
a 1
• Note that there can be un-used elements
e 2
in the co-domain
i 3
o 4
5
A one-to-one function
One to One Function
More on one-to-one
• Determine whether the function f form {a, b, c, d} to {1, 2, 3, 4, 5}
with f(a)= 4, f(b)= 5, f(c)= 1, f(d)= 3 is one-to-one or not.
• Determine whether the function f(x) = x2 from the set of integers to
the set of integers is one-to-one?
• Determine whether the function f(x) = x+1 from the set of integers to
the set of integers is one-to-one?
Onto functions
Definition
A function is onto if each element in the co-domain is an image of some
pre-image(s)
a 1 a 1
e 2 e 2
i 3 i 3
o 4 o 4
u 5
An onto function A function that
is not onto
Onto functions
More on onto
• Surjective is synonymous with onto
• “A function is surjective”
• A function is an surjection if it is onto
a 1
• Note that there can be multiple used e 2
elements in the co-domain i 3
o 4
u
An onto function
Onto functions
More onto
• Determine whether the function f form {a, b, c, d} to {1, 2, 3} with
f(a)= 3, f(b)= 2, f(c)= 1, f(d)= 3 is onto or not.
• Determine whether the function f(x) = x2 from the set of integers to
the set of integers is onto?
• Determine whether the function f(x) = x+1 from the set of integers to
the set of integers is onto?
Onto vs. one-to-one
Are the following functions onto, one-to-one, both, or neither?
a 1 a 1
a 1
b 2 b 2
b 2
c 3 c 3
c 3
4 d 4
4
1-to-1, not onto Both 1-to-1 and onto Not a valid function
a 1 a 1
b 2 b 2
c 3 c 3
d d 4
Onto, not 1-to-1 Neither 1-to-1 nor onto
Bijections
Definition
• A function that is both one-to-one and onto Such a function is a one-
to-one correspondence, or a bijection.
a 1
b 2
c 3
d 4
Bijections
• 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 bijection?
Identity functions
Definition
A function such that the image and the pre-image are ALWAYS equal
• f(x) = 1*x
• f(x) = x + 0
• The domain and the co-domain must be the same set
Inverse functions
Inverse functions
Let f(x) = 2*x
R f R
f-1
f(4.3)
4.3 8.6
f-1(8.6)
Then f-1(x) = x/2
Inverse functions
Definition
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 f-1 .
• Hence, f-1 (b) = a when f(a) = b
More on inverse
Inverse functions
functions
• Can we define the inverse of the following functions?
a 1 a 1
b 2 b 2
c 3 c 3
4 d
What is f-1(2)? What is f-1(2)?
Not onto! Not 1-to-1!
• An inverse function can ONLY be done defined on a bijection
Compositions of functions
(f ○ g)(x) = f(g(x))
f○g
A B C
g f
g(a) f(b)
a f(g(a))
b = g(a)
(f ○ g)(a)
Compositions of functions
Definition
• 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 f o g is defined by
(f o g)(a) = f(g(a))
Note that the composition f o g can not be defined unless the range of g is a subset
of the domain of f.
Compositions
Compositions of functions
of functions
Let f(x) = 2x+3 f○g
Let g(x) = 3x+2
R R R
g f
g(1) f(5)
f(g(1))=13
1
g(1)=5
(f ○ g)(1)
f(g(x)) = 2(3x+2)+3 = 6x+7
Compositions of functions
Compositions of functions
Does f(g(x)) = g(f(x))?
Let f(x) = 2x+3 Let g(x) = 3x+2
f(g(x)) = 2(3x+2)+3 = 6x+7
g(f(x)) = 3(2x+3)+2 = 6x+11
Useful functions
• Floor: x means take the greatest integer less than or equal to the
number
• Ceiling: x means take the lowest integer
greater than or equal to the number
• round(x) = x+0.5
Floor, Ceiling Examples
• Find these values
• 1 1
• 1 1
• -0.1 -1
• -0.1 0
26
End of Lesson
Thanks to all !!!