You are on page 1of 54

Discrete Structures

S. Y. B. Tech CSE

SCHOOL OF COMPUTER ENGINEERING AND TECHNOLOGY

DISCRETE STRUCTURES UNIT-II 1


Functions
Surjective, Injective and Bijective functions,
Inverse Functions and Compositions of
Functions, Recursive Function.

DISCRETE STRUCTURES UNIT-II 2


Functions
 Till today, We have studied

 Sets
 Counting
 Relations

DISCRETE STRUCTURES UNIT-II 3


Function : Example
Mathematical function: Finding square of an integer

DISCRETE STRUCTURES UNIT-II 4


Function : Example
C function: Finding square of an integer

DISCRETE STRUCTURES UNIT-II 5


Introduction
 Some well known function
 f(x,y) = x+y
 f(x) = |x|
 f(x) = sin(x)
 ....

 Here we will study functions defined on discrete


domains and ranges.

DISCRETE STRUCTURES UNIT-II 6


Definition of Functions
 Given any sets A, B, a function f from (or “mapping”) A to B
(f:AB) is an assignment of exactly one element f(x)B
to each element xA.
 Formally: given f:AB
“x is a function” : ( x,y: (x=y)  (f(x) = f(y)))

DISCRETE STRUCTURES UNIT-II 7


Functions: Example 1
A B
a1 b1
a2 b2
a3 b3
a4 b4

 Is this a function?
No, because each of a1, a3 has two images
DISCRETE STRUCTURES UNIT-II 8
Functions: Example 2

Which of above diagrams represent functions? Fig. (b) and (e)

DISCRETE STRUCTURES UNIT-II 9


Graphical Representations
 Functions can be represented graphically in
several ways:
f A B
• •
f • •
• • • y
a b •


• x
A B
Like Venn diagrams Graph Plot

DISCRETE STRUCTURES UNIT-II 10


Function: Visualization
Range Image, f(a)=b
Preimage
f
a b

A B
Domain Co-Domain

A function, f: A  B
DISCRETE STRUCTURES UNIT-II 11
Some Function Terminology
 If f:AB, and f(a)=b (where aA &
bB), then:
 A is the domain of f.
 B is the codomain of f.
 b is the image of a under f.
 a is a pre-image of b under f.
 In general, b may have more than one pre-
image.
 The range RB of f is {b | a f(a)=b }.
DISCRETE STRUCTURES UNIT-II 12
Range vs. Codomain: Example

 Suppose that: “f is a function mapping students in this


class to the set of birthday month
{Jan, Feb, Mar,Apr, May, Jun,July,Aug,Sep,Oct,Nov,Dec}.”
 At this point, you know f’s codomain is:
__________,
{Jan, Feb..Dec} and its range is ________.
unknown!

 Range {..,..}
 {Jan, Feb..Dec}
Codomain is __________________.
DISCRETE STRUCTURES UNIT-II 13
Sum and Product
 We can add and multiply functions
Let f,g: AR are two functions

 Sum:
(f  g): A R, where (f  g)(x) = f(x)  g(x)
 Product:
(f × g): A R, where (f × g)(x) = f(x) × g(x)

DISCRETE STRUCTURES UNIT-II 14


Sum and Product:Example
Example 1:
Let f1 and f2 be functions
f1 , f2 :RR

f1(x)=x2
f2(x)=x-x2
calculate (f1+f2)(x) and f1f2(x)
(f1+f2)(x) = x2+x-x2 = x (SUM)
f1f2(x) = (x2)(x-x2)= x3-x4 (PRODUCT)
DISCRETE STRUCTURES UNIT-II 15
Sum and Product:Example
Example 2:
Let f1 and f2 be functions
f1 , f2 :RR

f1(x)=x4+2x2+1
f2(x)=2-x2

Find values of (f1+f2)(x) and f1f2(x) for x=2

DISCRETE STRUCTURES UNIT-II 16


Function: Image of a set
 Definition: Let f: A B and S A. The
image of the set S is the subset of B that
consists of all the images of the
elements of S. We denote the image of
S by f(S), so that
f(S)={ f(s) |  sS}
 Note that the image of S is a set and not
an element.
DISCRETE STRUCTURES UNIT-II 17
Image of a set:Example
 Let A:wrestlers trained by Mahavir Singh Phogat
 B:Months, f:AB (Birth Months of wrestlers of set A)

 A = {Geeta, Babita, Priyanka, Ritu, Vinesh,Sangita}
 B = {Jan, Feb, Mar,Apr, May, Jun, July,Aug,Sep,Oct,Nov,Dec}
 f={(Geeta, December), (Babita, November), (Priyanka, May),
(Ritu, May), (Vinesh, August), (Sangita,March)}

 Let S={Geeta, Babita, Priyanka, Ritu}

 What is f(S)?
DISCRETE STRUCTURES UNIT-II 18
Function Equality
 Although it is intuitive, we formally
define what it means for two functions
to be equal
 Equality: Two functions f and g are
equal if and only
 dom(f) = dom(g)
  a dom(f) (f(a) = g(a))

DISCRETE STRUCTURES UNIT-II 19


Function Equality:Example
 Let f:AN and g:AN are two function
defined as:
f(x) = ( x2+ x) mod3
And g(x) = ( x3+ x2) mod 3
A={0,1,2}
 Whether these function are equal ? Justify
your answer

DISCRETE STRUCTURES UNIT-II 20


Types of functions
 One to one (Injection)
 Onto (Surjection)
 One to one /Onto (Bijection)

One to one Onto One to one and Onto

DISCRETE STRUCTURES UNIT-II 21


One-to-One Functions
 A function is one-to-one (1-1), or injective, or
an injection, iff every element of its range has
only one pre-image.
 Only one element of the domain is mapped to
any given one element of the range.
 Domain & range have same cardinality. What
about codomain?
 Formally: given f:AB
“x is injective” : ( x,y: (f(x)=f(y))  (x =y))

DISCRETE STRUCTURES UNIT-II 22


One-to-One Illustration
 Graph representations of functions that are
(or not) one-to-one:

• • • •
• • • • •
• • • •
• • • •
• • •
• • • •
• •

Not even a
One-to-one Not one-to-one function!

DISCRETE STRUCTURES UNIT-II 23


One to one Functions: Example 1
A B
a1 b1
a2 b2
a3 b3
a4

 Is this a function
 One-to-one (injective)? Why? No, b3 has 2 preimages

DISCRETE STRUCTURES UNIT-II 24


Sufficient Conditions for 1-1ness

 Definition: A function f whose domain and


codomain are subsets of the set of real numbers
(R) is called
 strictly increasing if f(x)<f(y) whenever x<y and x
and y are in the domain of f.
 E.g. f1 :RR f(x) = x+2
 strictly decreasing if f(x)<f(y) whenever x<y and x
and y are in the domain of f.
 E.g. f1 :RR f(x) = x-2
 A function that is increasing or decreasing is said
to be monotonic DISCRETE STRUCTURES UNIT-II 25
One-to-One Functions:Example2

 Let f:ZZ be defined by


f(x)=x2
Whether this function one to one?
No
 Let f:ZZ be defined by
f(x)=x3
Whether this function one to one?

Yes

DISCRETE STRUCTURES UNIT-II 26


Onto (Surjective) Functions
 A function f:AB is onto or surjective or a
surjection iff its range is equal to its
codomain (bB, aA: f(a)=b).
 An onto function maps the set A onto (over,
covering) the entirety of the set B, not just
over a piece of it.

DISCRETE STRUCTURES UNIT-II 27


Illustration of Onto
 Some functions that are or are not onto
their codomains:

• • • • • • • •
• • • • • • • •
• • • •
• • • •
• • • • • •
• • • •

Onto Not Onto Both 1-1 1-1 but


(but not 1-1) (or 1-1) and onto not onto
DISCRETE STRUCTURES UNIT-II 28
Functions: Example1
A B
a1 b1
a2 b2
a3 b3
a4 b4

 Is this a function
 One-to-one (injective)? Yes
 Onto (surjective)? Yes
DISCRETE STRUCTURES UNIT-II 29
Onto Functions: Example 2

 Let f:RR be defined by


f(x)= x2
Whether this function onto?
 Let f:RR be defined by

f(x)= x3
Whether this function onto?

DISCRETE STRUCTURES UNIT-II 30


One to one Onto(Bijection)

A function f is a one-to-one correspondence, or a


bijection, or reversible, or invertible, iff it is both
one-to-one and onto.
Some functions that are or are not bijective

• • • • • • • •
• • • • • • • •
• • • • • •
• • • •
• • • • • •
• •
Only Onto Not Onto Both 1-1 1-1 but
(but not 1-1) (or 1-1) and onto not onto
DISCRETE STRUCTURES UNIT-II 31
Functions: Example 1
A B
a1 b1
a2 b2
a3 b3
a4 b4

 Is this a function
 One-to-one (injective)? Thus, it is a bijection or a
 Onto (surjective)? one-to-one
correspondence
DISCRETE STRUCTURES UNIT-II 32
One to one Onto(Bijection)
:Example 2
 Let f:ZZ be defined by
f(x)= x+1
Whether this function bijective?
 Let f:RR be defined by

f(x)= x2
Whether this function one to one onto?

DISCRETE STRUCTURES UNIT-II 33


Functions: Example 3
 Let f:ZZ be defined by
f(x)=2x-3
 What is the domain, codomain, range of f?
 Is f one-to-one (injective)?
 Is f onto (surjective)?
 Clearly, dom(f)=Z. To see what the range is, note that:
b rng(f)  b=2a-3, with aZ
 b=2(a-2)+1
 b is odd

DISCRETE STRUCTURES UNIT-II 34


Functions: Example 3 (cont’d)
 Thus, the range is the set of all odd integers
 Since the range and the codomain are
different (i.e., rng(f)  Z), we can conclude
that f is not onto (surjective)
 However, f is one-to-one injective. Using
simple algebra, we have:
f(x1) = f(x2)  2x1-3 = 2x2-3  x1= x2

DISCRETE STRUCTURES UNIT-II 35


Composition: Graphical Representation

(f  g)(a)

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

A B C

The composition of two functions


DISCRETE STRUCTURES UNIT-II 36
Function Composition
Example 1:
 The value of functions  input to other
functions
 For functions g:AB and f:BC, there is a
special operator called compose (“○”).
 It composes a new function out of f,g by applying f to
the result of g.
(f○g):AC, where (f○g)(a) = f(g(a)).
 The range of g must be a subset of f’s domain!!
 Note that ○ is non-commuting. (In general, f○g 
g○f.)
DISCRETE STRUCTURES UNIT-II 37
Composition: Example1

 Given f(x) = 2x – 3 and g(x) = x2 + 1


 (f  g)(x) = ?

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

DISCRETE STRUCTURES UNIT-II 38


Composition: Example
Example 2:
 f(x) = 2x – 3
 g(x) = x2 + 1
 find (g  f)(x)

(g  f)(x) =

Conclusion ?

g(2x-3)
(2x-3)2 +1
4x2 - 12x + 10
f○g  g○f
DISCRETE STRUCTURES UNIT-II 39
Function Composition: Associativity

 The composition of functions is an associative


operation, that is
(f  g)  h = f  (g  h)
Example: For functions g:NN and f:NN and
h:NN defined as
f(x) = x2
g (x)= 3x +4
h(x)= 2x+1
Prove that (f  g)  h = f  (g  h)
DISCRETE STRUCTURES UNIT-II 40
Inverse Functions
 Definition: Let f: AB be a bijection.
The inverse function of f is the function
that assigns to an element bB the unique
element aA such that f(a)=b
 The inverse function is denote f-1.
 When f is a bijection, its inverse exists and
f(a)=b  f-1(b)=a

DISCRETE STRUCTURES UNIT-II 41


Inverse Functions: Representation

f(a)
a b
f -1(b)
A B
Domain Co-Domain
A function and its inverse
DISCRETE STRUCTURES UNIT-II 42
Inverse Functions: Example 1
 Let f:RR be defined by
f(x) = 2x – 3
 What is f-1?
1. We must verify that f is invertible, that is, is a
bijection. We prove that is one-to-one (injective)
and onto (surjective). It is.
2. To find the inverse, we use the substitution
 Let f-1(y)=x
 And y=2x-3, which we solve for x. Clearly, x= (y+3)/2
 So, f-1(y)= (y+3)/2

DISCRETE STRUCTURES UNIT-II 43


Inverse Functions: Example 2
Say f:RR Let f(x)=x2. What is f-1?
 Is f a bijection? Does its inverse exist?
– Answer: No
• Say in above function we specify that f: A B
where
A={xR |x0} and B={yR | y0}
– Is f a bijection? Does its inverse exist?
– Answer: Yes, the function becomes a bijection and
thus, has an inverse
DISCRETE STRUCTURES UNIT-II 44
Inverse Functions: Example 2
(cont’)
 To find the inverse, we let
 f-1(y)=x
 y=x2, which we solve for x
 Solving for x, we get x=y, but which one is it?
 Since dom(f) is all nonpositive and rng(f) is
nonnegative, thus x must be nonpositive and
f-1(y)= -y
 From this, we see that the domains/codomains are
just as important to a function as the definition of the
function itself

DISCRETE STRUCTURES UNIT-II 45


Inverse Functions: Example 3
 Let f(x)=2x
 What should the domain/codomain be for this
function to be a bijection?
 What is the inverse?
 The function should be f:RR+
 Let f-1(y)=x and y=2x, solving for x we get
x=log2(y). Thus, f-1(y)=log2(y)
 What happens when we include 0 in the
codomain?
 What happens when restrict either sets to Z?
DISCRETE STRUCTURES UNIT-II 46
Identity Function Illustrations
 The identity function: f:RR where
f(x) = x


• • y
• •
• •
• •

Domain and range x

DISCRETE STRUCTURES UNIT-II 47


Important Functions: Identity
 Definition: The identity function on a set A is
the function
: AA
defined by (a)=a for all aA.
 One can view the identity function as a
composition of a function and its inverse:
(a) = (f  f-1)(a) = (f-1  f)(a)
 Moreover, the composition of any function f
with the identity function is itself f:
(f   )(a) = (  f)(a) = f(a)
DISCRETE STRUCTURES UNIT-II 48
Recursion

DISCRETE STRUCTURES UNIT-II 49


Recursively Defined Functions
 One way to define a function f:NS (for
any set S) is to:
 Define f(0).
 For n>0, define f(n) in terms of f(0),…,f(n−1).
 E.g.: Define the series f(n)= 2n recursively:
 Let f(0) = 1.
 For n>0, let f(n) :≡ 2f(n-1).

DISCRETE STRUCTURES UNIT-II 50


The Fibonacci Series
 The Fibonacci series fn≥0 is a famous
series defined by:
f0 :≡ 0, f1 :≡ 1,
 fn≥2 :≡ fn−1 + fn−2

0
1 1
2 3
Leonardo Fibonacci
5 8 1170-1250
13 DISCRETE STRUCTURES UNIT-II 51
Important Function: Factorial
 Definition: The factorial function, denoted
n, is a function NN+. Its value is the
product of the n positive integers

n = i=1 i=n i = 123(n-1)n

1 if n = 0
f(n)= (recursive solution)
n*f(n-1) if n > 0

DISCRETE STRUCTURES UNIT-II 52


Takeaway
 Definitions & terminology
 function, domain, co-domain, image, preimage (antecedent), range,
image of a set, strictly increasing, strictly decreasing, monotonic
 Types of functions
 One-to-one (injective), onto (surjective), one-to-one correspondence
(bijective)
 Exercises
 Inverse functions and Identity
 Operators
 Composition, Equality
 Recursive functions
 Fibonacci, factorial

DISCRETE STRUCTURES UNIT-II 53


References
 http://cse.unl.edu/~choueiry/F08-
235/files/Functions.ppt
 www.mhhe.com/rosen

DISCRETE STRUCTURES UNIT-II 54

You might also like