0% found this document useful (0 votes)
7 views25 pages

9 Functions Copy

Uploaded by

ar.rehman7240
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views25 pages

9 Functions Copy

Uploaded by

ar.rehman7240
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

Discrete Structures

Functions
Muhammad Shafiq

1
Recall the Cartesian Product

• All ordered n-tuples (2 tuples in our example)


• Let S = { Ali, Babar, Chishti } and G = { A, B, C }
• S×G = { (Ali, A), (Ali, B), (Ali, C), (Babar, A), (Babar, B),
(Babar, C), (Chishti , A), (Chishti , B), (Chishti , C) }
– A relation
• The final grades will be a subset of this:
– { (Ali, C), (babar, B), (Chishti, A) }

2
Grade Assignment
Ali A
Babar B
Chishti C

Ali A
Babar B
Chishti C

3
Function
• This assignment is an example of a function

• A function is a set of ordered pairs in which each


x-element has only ONE y-element associated
with it

• The concept of a function is extremely important


in mathematics and computer science

4
Definition 1
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.

We write f (a) = b if b is the unique element of B


assigned by the function f to the element a of A.

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

5
Specifying a Function

Many different ways:


• Sometimes we explicitly state the assignments,
as in previous figure
• Often we give a formula, such as f (x) = x + 1, to
define a function
• Other times we use a computer program to
specify a function

6
Definition 2
• 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.

Domain A B Co-domain
f

f(4.3)
4.3 4

7
Definition 2
• If f (a) = b, we say that b is the image of a and
a is a preimage of b.
Domain R Z Co-domain
f

f(4.3)
4.3 4

8
Pre-image of 4 Image of 4.3
Definition 2
• If f is a function from A to B, we say that f
maps A to B. f maps R to Z
R f:A→B Z
Domain Co-domain
f

f(4.3)
4.3 4

Pre-image of 4 Image of 4.3


9
Examples
A pre-image The image
Domain Co-domain of 1 of “a”
Ali A “a” 1

Babar B “bb“ 2

Chishti C “cccc” 3

Dawood D “dd” 4

Ammara 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(Chishti) = A f(“bb”) = 2
… …
Definition 2
• The range of f is the set of all images of
elements of A.
Range
a 1
e 2
i 3
o 4
u 5

Some function…

11
Not a valid function!

“a” 1
“bb“ 2
“cccc” 3
“dd” 4
“e” 5
Exercise
• 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 ?
– St of all integers
• What is the range of f ?
– {0, 1, 4, 9, . . . }. All integers that are perfect squares
13
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 × g)(x)
• (f/g)(x) = f(x)/g(x) given that g(x)≠0 14
Example
• Let f1 and g be functions from R to R such that:
• f(x) = x2 //square function
• g (x) = x − x2 //some other function
• What are the functions f + g and f g?
• f + g = (f + g)(x) = f (x) + g(x) = x2 + (x − x2) = x
• (f g) = (f g)(x) = f(x)g(x) = x2(x − x2) = x3 − x4
• What is f(x)+g(x) and f+g(x) if x=2?
• f(2)=4, g(2)=-2; f(2)+g(2) = 4-2=2
• f+g(2) = 2 15
Another Example
• Let f and g be functions from R to R such that:
• f (x) = 3x+2
• g (x) = -2x + 1
• What is the function f g?

• f g = (f g) (x) = f (x)g(x) = (3x+2)(-2x+1) = -6x2- x +2


Let x = -1, what is f(-1).g(-1) and (f g)(-1)?
f (-1) = 3(-1) + 2 = -1 (f g) (-1) = -6(-1)2 – (-1) + 2
g(-1) = -2(-1) + 1= 3 = -6+1+2
f(-1) g(-1) = -1×3 = -3 = -3 16
One-to-one functions
• 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(x) = f(y) implies x = y.
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 17
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 e 2

be un-used elements i 3
o 4
in a co-domain 5

A one-to-one function

18
Exercise
• Determine that the function f(x) = x2 of
type Z × Z is one-to-one.

• 0 -> 0
• 1 -> 1
• 2 -> 4
• 3 -> 9
• 10 -> 100

19
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

An onto function A function that


is not onto
20
More on onto
• Surjective is synonymous with onto
– “A function is surjective”
• A function is a surjection if it is onto

• Note that there can a 1


be multiple used e 2

elements in the i 3
o 4
co-domain u

An onto function
21
Exercise
• Determine that the function f(x) = x2 of type Z × Z
is onto?
• No 0 0
1 1
2 2
3 3
⁞ 4
5
6

22
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
23
Bijections
• Consider a function that is
both one-to-one and onto: a 1
b 2
c 3
• Such a function is a one-to-
d 4
one correspondence, or a
bijection

24
• A relation is an Equivalence Relation if it is
reflexive, symmetric, and transitive.

• Example − The relation R={(1,1),(2,2),(3,3),(1,2),


(2,1),(2,3),(3,2),(1,3),(3,1)}
• on set A={1,2,3} is an equivalence relation since it
is reflexive, symmetric, and transitive.

25

You might also like