Function
Function
CPCS 222
Discrete Structures I
Functions
3
Functions
A for Mohamed,
C for Ahmed,
B for Taha,
A for Emad, and
F for Salah.
Mohamed A
Ahmed B
Taha C
Emad D
Salah F
4
Functions
6
Functions
If f is a function from A to B,
we say that
A is the domain of f and
B is the codomain of f.
If f (a) = b, we say that
b is the image of a and
a is a preimage of b.
The range of f is the set of all images of
elements of A.
Also, if f is a function from A to B, we say
that f maps A to B
7
Functions
8
Functions
When we define a function we specify
its domain,
its codomain, and
the mapping of elements of the domain
to elements in the codomain.
10
Functions
Mohamed A
Ahmed B
Taha C
Emad D
Salah F
13
Functions
Let f be the function that assigns the last
two bits of a bit string of length 2 or
greater to that string.
14
Functions
Sum and Product of functions
( f1f2)(x) = f1(x)f2(x).
15
Functions
Let f1 and f2 be functions from R to R such
that f1(x) = x2 and f2(x) = x − x2.
What are the functions f1+f2 and f1f2?
16
Functions
One-to-One Functions
Some functions never assign the same value to
two different domain elements. These
functions are said to be one-to-one.
using quantifiers
f is one-to-one
∀a∀b( f (a) = f (b) → a = b)
or equivalently
∀a∀b(a ≠ b → f (a) ≠ f (b)),
where the universe of discourse is the domain
of the function
18
Functions
One-to-One Functions (Examples)
Determine whether the function f from
{a, b, c, d} to {1, 2, 3, 4, 5} with f (a) = 4, f
(b) = 5, f (c) = 1, and f (d) = 3 is one-to-one.
The function f is one-to-one because f takes
on different values at the four elements of
its domain.
A One-to-One
Function
19
Functions
One-to-One Functions (Examples)
Determine whether the function f (x) = x2 from
the set of integers to the set of integers is
one-to-one.
The function f (x) = x2 is not one-to-one
because, for instance, f (1) = f (−1) = 1, but
1 ≠ −1.
20
Functions
One-to-One Functions (Examples)
Determine whether the function f (x) = x2 from
the set of positive integers to the set of
positive integers is one-to-one.
The function f (x) = x2 is one-to-one
because, for instance, f (1) = 1, f (2) = 4,
….
f takes on different values at the all elements
of its domain.
22
Functions
One-to-One Functions
We now give some conditions that guarantee
that a function is one-to-one
A function f whose domain and codomain are
subsets of the set of real numbers is called
increasing if f(x) ≤ f(y), and strictly
increasing if f(x) < f(y), whenever x < y and
x and y are in the domain of f.
23
Functions
One-to-One Functions
Similarly, f is called decreasing if f(x) ≥ f(y),
and strictly decreasing if f(x) > f(y), whenever
x<y and x and y are in the domain of f.
A function f is increasing if
∀x∀y(x < y → f(x) ≤ f(y)),
strictly increasing if
∀x∀y(x < y → f(x) < f(y)),
decreasing if ∀x∀y(x < y → f(x) ≥ f(y)), and
strictly decreasing
if ∀x∀y(x < y → f(x) > f(y)), where the
universe of discourse is the domain of f 24
Functions
One-to-One Functions
From these definitions, we see that a function
that is either strictly increasing or strictly
decreasing must be one-to-one.
25
Functions
Onto Functions
A function f from A to B is called onto, or
surjective, if and only if
for every element b ∈ B
there is an element a ∈ A with f(a) = b.
27
Functions
Onto Functions (Examples)
Is the function f(x) = x2 from the set of
integers to the set of integers onto?
28
Functions
Onto Functions (Examples)
Is the function f(x) = x + 1 from the set of
integers to the set of integers onto?
29
Functions
One-to-One and Onto Functions
The function f is a one-to-one correspondence,
or a bijection,
bijection if it is both one-to-one and
onto.
30
Functions
One-to-One and Onto Functions (Examples)
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 a bijection?
37
Functions
Inverse of Functions (Examples)
38
Functions
Inverse of Functions (Examples)
40
Functions
Inverse of Functions (Examples)
42
Functions
Composition of Functions
(f◦g)(a) = f (g(a)).
43
Functions
Composition of Functions
44
Functions
Composition of Functions
45
Functions
Composition of Functions (Examples)
f◦g ≠ g◦f (the commutative law does not hold for the
composition of functions)
47
Functions
Composition of Function with its inverse
When the composition of a function and its inverse is
formed, in either order, an identity function is obtained.
To see this, suppose that f is a one-to-one
correspondence from the set A to the set B. Then the
inverse function f−1 exists and is a one-to-one
correspondence from B to A.
The inverse function reverses the correspondence of the
original function, so f −1(b) = a when f(a) = b, and
f(a) = b when f−1(b) = a. Hence,
(f−1◦f)(a) = f−1(f(a)) = f−1(b) = a, and
(f◦f−1)(b) = f(f−1(b)) = f(a) = b.
f−1◦f = IA and f◦f −1 = IB, where IA and IB are the
identity functions on the sets A and B, respectively.
48
That is, (f ) = f .
−1 −1
Functions
The Graphs of Functions
f(n)
n
50
Functions
The Graphs of Functions (Examples)
Display the graph of the function f(x) = x2 from the set
of integers to the set of integers.
The graph of f is the set of ordered pairs of the form
(x, f(x)) = (x, x2), where x is an integer.
f(x)
x
51
Functions
Some Important Functions
The floor function assigns to the real number x the
largest integer that is less than or equal to x.
The value of the floor function at x is denoted by x
The floor function (the greatest integer function) [x]
rounds x down to the closest integer x
52
Functions
Some Important Functions
The ceiling function assigns to the real number x the
smallest integer that is greater than or equal to x.
The value of the ceiling function at x is denoted by x.
the ceiling function
rounds x up to the closest integer x.
53
Functions
Some Important Functions (Example)
Data stored on a computer disk or transmitted over a
data network are usually represented as a
string of bytes. Each byte is made up of 8 bits. How
many bytes are required to encode 100 bits of data?
56
Functions
x + n = x + n
Assume x = ½ and y = ½
x + y= ½ + ½ = 1 =1
But x + y = ½ + ½ = 1+1= 2
58
Functions
Prove that if x is a real number,
then 2x = x + x + ½
let x = n + , where n is a positive integer
and 0 ≤ < 1.
There are two cases to consider, depending on whether
is less than or greater than or equal to ½
the case when 0 ≤ < ½
2x = 2n + 2 and 2x = 2n because 0 ≤ 2 < 1.
Similarly, x + ½ = n + (½+ ), so x + ½ = n,
because 0 ≤ ½+ < 1
Consequently, 2x = 2n and x + x + ½ =n+n= 2n.
59
Functions
Prove that if x is a real number,
then 2x = x + x + ½
let x = n + , where n is a positive integer
and 0 ≤ < 1.
the case when ½ ≤ < 1
2x = 2n + 2 = (2n + 1) + (2 − 1),
it follows that 2x = 2n+1 Because 0 ≤ 2 − 1 < 1
x + ½ = n+(½+
n+( ) = n+1+(
n+1+( -½)
- and 0 ≤ − ½ < 1
it follows that x + ½ =n + 1. Consequently,
2x = 2n + 1 and x + x + ½ = n + (n + 1) = 2n + 1.
60
Chapter 2 Exercises
Pages 2-(36-38)
1-7(a,c)
8,9 (a,h)
10-13
61