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

L16 17 Functions

Uploaded by

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

L16 17 Functions

Uploaded by

Itachi Uchiha
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 50

CSC102 - Discrete Structures

(Discrete Mathematics)
Lecture # 16
Chapter 2.3

Functions
Lecture Outline

• Functions
– What is a function?
– Function Arithmetic
– One-to-one, Onto and Bijective Functions
– Identity and Inverse Function
– Composition of Functions

12/05/2024 CSC102 - Discrete Structures 3


Application of Functions

• Define discrete structures such as sequences


and strings
• Represent the time that a computer takes to
solve problems of a given size
• Represent the complexity of algorithms
• …
Functions

• Each student in a discrete structures class is


assigned a letter grade from the set {A, B, C, D,
F}.
• This assignment is an example of a function.

Ali A
Babar B
Umer C
Imran D
Hamza F
Functions
• Let A and B be nonempty sets.

• A function f from A to B is an assignment of exactly


one element of B to each element of A.

• If b is the unique element of B assigned by the


function f to the element a of A, we write f(a) = b.

• If f is a function from A to B, we write f: A B.


Arrow Diagram of Functions

2 12
The arrow diagram for a function f 3 20
has the following two properties: 4 24
5 8
• Every element of A has an arrow 6 16
coming out of it.
• No elements of A has two arrows
coming out of it that point to two
different elements of B.
Functions and Non-Functions
• Which of the arrow diagrams define functions from
• A = {2,4,5,6,7} to B = {1,2,4,6,8}.

Domain Co-domain Domain Co-domain


2 1
2 1
4 2
4 2
5 4
5 4
6 6
6 6
7 8
7 8

A B A B

Not a Function Not a Function


Functions
• 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

Pre-image of 4 Image of 4.3


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
the pre-image of b.
• The range of f is the set of all images of
elements of A.
• Also, if f is function from A to B, we say that f
maps A to B.
Arrow Diagram – Function Terminologies

The pre-image The image


Domain Co-domain of 1 of “a”
Ali A “a” 1

Babar B “bb“ 2

Umer C “cccc” 3

Hamza D “dd” 4

Amir F “e” 5

A class grade function A string length function

g(Ali) = A f(x) = length x


g(Babar) = C f(“a”) = 1
g(Umer) = A f(“bb”) = 2
… …
Arrow Diagram – Function Terminologies

The range of f is the set of all images of elements of


A.

Domain Range
a 1
e 2
i 3 Co-domain
o 4
u 5
Example
• Let f : Z → Z : assign the square of an integer to this
integer
• What is f (x) =?
– f(x) = x2
• What is domain of f ?
– Set of all integers
• What is codomain of f ?
– Set of all integers
• What is the range of f ?
– {0, 1, 4, 9, . . . }. All integers that are perfect
squares
One-to-One Function-Injective
• A function is one-to-one if each element in the
co-domain has a unique pre-image
• Formal definition: A function f is one-to-one if
f(a) = f(b) implies a = b for all a and b in the
domain of f.
a 1
a 1 e 2
e 2 i 3
i 3 o 4
o 4 5
5
A function that is
A one-to-one function not one-to-one
One-to-One Function-Injective

• is one-to-one using quantifiers as

or equivalently

a 1
e 2
Note that there can be un-used i 3
elements in the co-domain o 4
5
A one-to-one function
Example - one-to-one (Injective)

• Determine whether the function from to with is one-


to-one.
Onto Functions- Surjective
• 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
b  B, there exists a  A such that f(a) = b.

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- Surjective

• A functionis onto if , where the domain for is


the domain of the function and the domain
for is the codomain of the function.

a 1
e 2
Note that there can be multiple i 3
used elements in the co-domain o 4
u

An onto function
Example onto (Surjective) function

• Determine whether the function from to


defined by
. Is an onto function?
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
Example
• Determine whether the function f (x) = from the set
of integers to the set of integers is one-to-one.
Example
• Determine whether the function f (x) = from the set
of integers to the set of integers is onto.
Bijections OR One-to-One Correspondence

• A function that is both one-to-one and onto is a one-to-


one correspondence, or a bijection.
a 1
b 2
Example: c 3
Determine whether the following d 4
functions are bijective or not?
Function Arithmetic
• Just as we are able to add (+), subtract (-), multiply (*), and
divide (÷) two or more numbers, we are able to + , - , * , and ÷
two or more functions.

• Let f and g be functions from A to R. Then f + g, f – g, f * g


and f/g are also functions from A to R defined for all x ∈ A by:
• (f + g)(x) = f(x) + g(x)
• (f - g)(x) = f(x) - g(x)
• (f *g)(x) = f (x)*g(x)
• (f/g)(x) = f(x)/g(x) given that g(x)≠0
Function Arithmetic
• Let f1 and f2 be functions from R to R such that:
f1(x) = 2x f2(x) = x2

f1+f2 = (f1+f2)(x) = f1(x)+f2(x) = 2x+x2


f1*f2 = (f1*f2)(x) = f1(x)*f2(x) = 2x*x2 = 2x3

• Let f and g be functions from R to R such that:


f (x) = 3x+2 g (x) = -2x + 1
f*g = (f*g) (x) = f (x)*g(x) = (3x+2)*(-2x+1)
= -6x2- x +2
Function Arithmetic

• let f(x)=5x+2 and g(x)=x2 -1,


At x=4, f(4)=22 and g(4)=15.
Arithmetic Expression Combine evaluate Evaluate, then combine
(f+g)(x) (f+g)(4) f(4)+g(4)
(5x+2) + (x2-1) 42+5(4)+1 =16+20+1 22+15
=x2+5x+1 =37 =37
(f-g)(x) (f-g)(4) f(4)-g(4)
(5x+2) - (x2-1) -42+5(4)+3 22-15
=-x2+5x+3 =-16+20+3 =7 =7
(f*g)(x) (f*g)(4) f(4)*g(4)
(5x+2)*(x2-1) 5(43)+2(42)-5(4)-2 22*15
=5x3+2x2-5x-2 =5(64)+2(16)-20-2 =330 =330
(f/g)(x) (f/g)(4) f(4)/g(4)
(5x+2)/(x2-1) [5(4)+2]/[42-1] 22/15
=22/15
Some Useful Function-Floor and Ceiling
• Floor(x) = is the largest integer that is less than or
equal to x.
• Ceiling(x) = is the smallest integer that is greater
than or equal to x
• The floor and ceiling functions give you the nearest
integer up or down.
Sample value
Floor Ceiling
x
12/5 = 2.4 2 3
2.7 2 3
−2.7 −3 −2
−2 −2 −2
Some Useful Function-Floor and Ceiling

How many bytes are required to encode n bits of data


where n equals

a) 7? b) 1001? c) 28,800?
Some Useful Function-Factorial

• Factorial is denoted by n!

• n! = n * (n-1) * (n-2) * … * 2 * 1

• Thus, 6! = 6 * 5 * 4 * 3 * 2 * 1 = 720

• Note that 0! is defined to equal 1


Some Useful Function-Identity Functions

• 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 Function

• 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 in b belonging to B the
unique element a in A such that f(a) = b.
• The inverse function of f is denoted by
• Hence , (b) = a when f(a) = b.
Inverse Functions

If f(a) = b, then f-1(b) = a

A B

f
a= f-1(b) f(a)=b
f-1

A=domain of f B=Co-domain of f
Inverse Functions

If f(x) = y, then f-1(y) = x


Let f(x) = 2*x
f(x)=y
R f R

f-1
f(4.3)
4.3 8.6
f-1(8.6)

Then f-1(y) = y/2


More on Inverse 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
More on Inverse Functions

• A one-to-one correspondence is called


invertible because we can define an inverse of
this function.

• A function is not invertible if it is not a one-to-


one correspondence, because the inverse of
such a function does not exist.
Example

• Let f be the function from {a, b, c} to {1, 2, 3}


such that
f (a) = 2, f (b) = 3, and f (c) = 1.
• Is f invertible, and if it is, what is its inverse?
Example

• Let g be the function from {a, b, c, d} to {1, 2,


3, 4}
such that
g(a) = 3, g (b) = 4, g(c) = 1, and g(d) = 3.
• Is g invertible, and if it is, what is its inverse?
Working Rule to Find Inverse Function

• Let f: X Y be a one-to-one correspondence


defined by the formula f(x) = y.
1. Solve the equation f(x) = y for x in terms of y.
2. (y) equals the right hand side of the equation
found in step 1.
Example- Inverse Function
Example- Inverse Function

• Find the inverse function of f(x) = x3+ 1.


Compositions of Functions

• 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 compositions of the functions f and
g, denoted by f g, is defined by
Compositions of Functions

(f g)(a) = f(g(a))

fg
A B C
g f

g(a) f(b)
a f(g(a))
b = g(a)

(f g)(a)
Compositions of Functions

Let g(x) = 3x+2 Let f(x) = 2x+3


f g
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

Do 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


Not equal!
g(f(x)) = 3(2x+3)+2 = 6x+11

Function composition is not commutative!


Example-Compositions of Functions

• Find f ◦ g and g◦f,


where f(x) = x2+ 1 and g(x) = x + 2, are
functions from R to R.

• Find f + g and f.g for the functions f and g


given in
Examples-Compositions of Functions
• Let A = {1,2,3,4,5}
f : A A and g : A A
f(1) = 3, f(2) = 5, f(3) = 3, f(4) = 1, f(5) = 2
g(1) = 4, g(2) = 1, g(3) = 1, g(4) = 2, g(5) = 3
Find the composition functions f ◦ g and g ◦ f .
f◦g g◦f
(f ◦ g ) (1) = f(g(1)) = f(4) =1 (g ◦ f ) (1) = g(f(1)) = g(3) = 1
(f ◦ g ) (2) = ? (g ◦ f ) (2) = ?
(f ◦ g ) (3) = ? (g ◦ f ) (3) = ?
(f ◦ g ) (4) = ? (g ◦ f ) (4) = ?
(f ◦ g ) (5) = ? (g ◦ f ) (5) = ?
Compositions of Functions
• Let A = {1,2,3,4,5}
f : A A and g : A A
f(1) = 3, f(2) = 5, f(3) = 3, f(4) = 1, f(5) = 2
g(1) = 4, g(2) = 1, g(3) = 1, g(4) = 2, g(5) = 3
Find the composition functions f ◦ g and g ◦ f .
f◦g g◦f
(f ◦ g ) (1) = f(g(1)) = f(4) =1 (g ◦ f ) (1) = g(f(1)) = g(3) = 1
(f ◦ g ) (2) = 3 (g ◦ f ) (2) = 3
(f ◦ g ) (3) = 3 (g ◦ f ) (3) = 1
(f ◦ g ) (4) = 5 (g ◦ f ) (4) = 4
(f ◦ g ) (5) = 3 (g ◦ f ) (5) = 1
Compositions of Functions

Let g : A A be the function, Set A = {a, b, c} such


that g(a) = b, g(b) = c, and g(c) = a.

Let f : A B be the function, Set A = {a, b, c} to the


set B = {1, 2, 3} such that f (a) = 3, f (b) = 2, and f
(c) = 1.

What is the composition of f and g, and what is


the composition of g and f?
Compositions of Functions
Let g : A A be the function, Set A = {a, b, c} such that g(a) = b, g(b) = c, and g(c)
= a.

Let f : A B be the function, Set A = {a, b, c} to the set B = {1, 2, 3} such that f (a) =
3, f (b) = 2, and f (c) = 1.

What is the composition of f and g, and what is the composition of g and f?


Solution:
The composition f ◦ g is defined by
(f ◦ g)(a) = f (g(a)) = f (b) = 2,
(f ◦ g) (b) = f (g(b)) = f (c) = 1,
(f ◦ g)(c) = f (g(c)) = f (a) = 3.
g ◦ f is not defined, because the range of f is not a subset of
the domain of g.
Reading and Exercise Questions

Topic # 2.3
Questions 1, 2, 8, 9,10,11,12, 22, 23, 38, 39

You might also like