DM Set04 Functions
DM Set04 Functions
Tassos Dimitriou
CpE-203
Discrete Structures
Set 4
Tassos Dimitriou
Outline
Functions
Definitions and properties
Types of functions
One-to-one, onto, bijections
Inverse functions
Composite
1
1/17/2019
Tassos Dimitriou
Functions
In many instances we assign to each element of a set a
particular element of a second set.
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 Bob, A for
Chris, E for Dave, and D for Emma.
Tassos Dimitriou
Functions
A function f from a set A to a set 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.
2
1/17/2019
Tassos Dimitriou
Tassos Dimitriou
Definition of a function
A function takes an element from a set and maps it to a
UNIQUE element in another set
f maps R to Z
Domain R Z Co-domain
f
f(4.3)
4.3 4
3
1/17/2019
Tassos Dimitriou
Range
a 1 “a” 1
e 2 “bb“ 2
i 3 “cccc” 3
o 4 “dd” 4
u 5 “e” 5
Some function…
Tassos Dimitriou
Definition of a function
If the domain of our function f is large, it is convenient to specify f
with a formula, e.g.:
f: RR
f(x) = 2x
4
1/17/2019
Tassos Dimitriou
Function arithmetic
Let f1 and f2 be functions from A to R. Then the sum and
the product of f1 and f2 are also functions from A to R
defined by
(f1 + f2)(x) = f1(x) + f2(x)
(f1f2)(x) = f1(x) * f2(x)
Tassos Dimitriou
One-to-one functions
A function is one-to-one if each element in the co-domain
has a unique pre-image (the function never assigns the
same value to two different domain elements)
Formal definition: A function f is one-to-one if f(x) = f(y)
implies x = y.
a 1 a 1
e 2 e 2
i 3 i 3
o 4 o 4
5 5
5
1/17/2019
Tassos Dimitriou
More on one-to-one
Injective is synonymous with one-to-one
“A function is injective”
A function is an injection if it is one-to-one
a 1
Note that there can be un-used e 2
elements in the co-domain i 3
o 4
5
A one-to-one function
Tassos Dimitriou
Onto functions
A function is onto if each element in the co-domain is an
image of some pre-image
Formal definition: A function f is onto if for all y C,
there exists x D such that f(x)=y.
a 1 a 1
e 2 e 2
i 3 i 3
o 4 o 4
u 5
6
1/17/2019
Tassos Dimitriou
More on “onto”
Surjective is synonymous with onto
“A function is surjective”
A function is an surjection if it is onto
a 1
An onto function
Tassos Dimitriou
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
7
1/17/2019
Tassos Dimitriou
Summary
Tassos Dimitriou
Identity functions
A function such that the image and the pre-image are
ALWAYS equal
f(x) = 1*x
f(x) = x + 0
8
1/17/2019
Tassos Dimitriou
Bijections
Consider a function that is both a 1
one-to-one and onto: b 2
c 3
d 4
Tassos Dimitriou
Inverse functions
f-1
f(4.3)
4.3 8.6
f-1(8.6)
9
1/17/2019
Tassos Dimitriou
Tassos Dimitriou
Compositions of functions
Consider two functions, the successor function and the
squaring function, defined over the integers, and imagine that
each is represented by a machine.
10
1/17/2019
Tassos Dimitriou
Compositions of functions
The composition of two functions g:AB and f:BC, denoted
by f◦g, is defined by
(f◦g)(a) = f(g(a))
Tassos Dimitriou
Compositions of functions
(f ○ g)(x) = f(g(x))
f○g
A B C
g f
g(a) f(b)
f(g(a))
a
b = g(a)
(f ○ g)(a)
11
1/17/2019
Tassos Dimitriou
Compositions of functions
(f ○ g)(x) = f(g(x))
Let f(x) = 2x+3 Let g(x) = 3x+2
f○g
R R R
g f
g(1) f(5)
f(g(1))=13
1
g(1)=5
(f ○ g)(1)
Tassos Dimitriou
Compositions of functions
Is f(g(x)) = g(f(x))?
12
1/17/2019
Tassos Dimitriou
Useful functions
Floor: x means take the greatest integer less than or
equal to the number
Round(x) = x+0.5
Tassos Dimitriou
13
1/17/2019
Tassos Dimitriou
Factorial
Factorial is denoted by n!
n! = n * (n-1) * (n-2) * … * 2 * 1
Thus, 6! = 6 * 5 * 4 * 3 * 2 * 1 = 720
Tassos Dimitriou
14
1/17/2019
Tassos Dimitriou
Graphs
The graph of a function f:AB is the set of ordered pairs
{(a, b) | aA and f(a) = b}.
Tassos Dimitriou
Cardinality of Sets
15
1/17/2019
Tassos Dimitriou
Cardinality of sets
Which is bigger the set of natural numbers N or the set
of integers Z?
Tassos Dimitriou
Cardinality
For finite (only) sets, cardinality is the number of elements in
the set
For finite and infinite sets, two sets A and B have the same
cardinality if there is a one-to-one correspondence from A to B
When A and B have the same cardinality, we write |A| = |B|.
16
1/17/2019
Tassos Dimitriou
Cardinality
Example on finite sets:
Let S = { 1, 2, 3, 4, 5 }
Let T = { a, b, c, d, e }
There is a one-to-one correspondence between the sets
Tassos Dimitriou
More definitions
Countable set (elements can be listed):
A set that is either finite or
Has the same cardinality as the set of positive integers (must find
a one-to-one correspondence with the Z+)
Example: rational numbers, ordered pairs of integers
17
1/17/2019
Tassos Dimitriou
Examples
Even numbers
Hilbert’s Grand Hotel
The famous mathematician David Hilbert invented the notion of the Grand
Hotel, which has a countably infinite number of rooms, each occupied by a
guest.
In a hotel with a finite number of rooms where all rooms are occupied, a new
guest cannot be accommodated without evicting a current guest.
However, we can always accommodate a new guest at the Grand Hotel.
How?
Tassos Dimitriou
When there are finitely many rooms in a hotel, the notion that all rooms are
occupied is equivalent to the notion that no new guests can be accommodated.
However, Hilbert’s paradox of the Grand Hotel can be explained by noting that
this equivalence no longer holds when there are infinitely many rooms.
18
1/17/2019
Tassos Dimitriou
Cardinality game
Which is bigger the set of natural numbers N or the set of
integers Z?
Tassos Dimitriou
Z is countable
19
1/17/2019
Tassos Dimitriou
Now form a new real number r = 0.d1d2d3… that differs in the diagonal
digit of all the listed numbers. Does r belong to the list?
No! Hence the assumption that all the real numbers between 0 and 1
could be listed is false. So the set of real numbers between 0 and 1 is
uncountable
CpE-203: Discrete Structures 39
Tassos Dimitriou
Matrices
20
1/17/2019
Tassos Dimitriou
Matrices
In mathematics, a matrix (plural matrices) is a rectangular
array of numbers, symbols, or expressions, arranged in rows
and columns. The individual items in a matrix are called its
elements or entries.
Tassos Dimitriou
Matrix Arithmetic
Definition: Let A= [aij] and B=[bij] be mn matrices. The sum of
A and B, denoted by A+B, is the mn matrix that has aij+bij as
its (i,j)th element.
A B A+B
21
1/17/2019
Tassos Dimitriou
Tassos Dimitriou
Matrix product
22
1/17/2019
Tassos Dimitriou
Tassos Dimitriou
23
1/17/2019
Tassos Dimitriou
A symmetric matrix
Tassos Dimitriou
Zero-One Matrices
Zero-one matrix: a matrix with entries that are either 0 or 1
24
1/17/2019
Tassos Dimitriou
Tassos Dimitriou
25