Functions - ComMSc
Functions - ComMSc
In Computer Science
Functions
By
Naleen Ganegoda
Department of Mathematics
University of Sri Jayewardenepura
Functions
At the end of this lesson you will be able to
Rule
A B
(Domain) (Codomain)
f
Notation : f : A B or A B
x squaring y x 2
So, rule can be expressed as f(x) x 2 , where generally f(x)
is for " function of x ". Alternativ ely it can be denoted by
x x 2 as well.
1 1
1 2
2 3
4
Ex. Denote the function t hat raises elements to the power 4
from the set of real numbers to the set of non - negative
real numbers.
f : 0 (or 0 or 0 )
f(x) x 4
Remark : There are rules which do not describe a function.
eg. Rule : assign x to a value whose square is equal to x .
x
x
x
This is not a unique assignment .
So, it cannot be a rule of a function.
Remark : Because of the unique assignment in a function,
different outputs are associated with different inputs.
To convince this feature, functions are said to be
" single - valued " or " well - defined " . Then, the other
rules without t he unique assignment may be reffered as
" multi - valued " .
Range of a function
Let f be a function w ith f : A B. Suppose a A is
assigned to b B by f ( ie. f(a) b). Then b is called the
image of a. Set of all images of the elements in the domain
is called the range of the function. Usually, it is denoted by
f (A) . Note that f (A) B.
Ex . Let f : f (0) 0
f ( x) x f ( 1) f (1) 1
f ( 2) f (2) 2
What is the range of f ?
Thus, we have only non - negative integers as images.
So, Range of f 0 (or 0 or 0 ).
Ex. f :
What is the range of f
i. if f ( x) x i. Range -0
ii. if f ( x) x 1 ii. Range (or )
iii. if f ( x) x 1 ? iii. Range 0
Ex. Let f ( x) 1 x 2
i. What is the minimum restrictio n on x which
defines a domain for the rule f ( x) ?
1 x 1
Domain of f x | x , 0 x 2
graph of f
y
( y f ( x))
0 X
x
Once we set a function as y f ( x), x is called the
independent variable and y is called the dependent
variable.
eg. What is the rule of the function plotted in the following
figure ? Determine the domain and the range.
Y
X
1 0 1
Rule : f ( x) x 1
Domain : x | x , 1 x 1
Range : y | y , 0 y 2
0 X
1 2 3 4
eg. If f ( x ) x 2 1 ; 2 x 4 and
2
g( x ) ; 0 x 5.
x 3
Comment on rule and domain for f g and g .
f
Then, the rule for f g : f g x
f x g x
2 2
x 1
x 3
the domain for f g : 0 x 4
Here, f g .
1 ; x \
If g ( x) is changed as g (x)
0 ; x
function f function g
x f (x) g ( f ( x))
output of f
becomes input for g
Consider t he functions f : A B and g : B C .
Then, the compositio n of f and g , denoted by g O f ,
is the function g O f : A C defined by
g O f x g ( f ( x)) .
We read g O f as " g circle f " or " g of f " .
g f
Ultimately , compositio n can be seen as a " function
of a function " .
2
eg. If the rules are given by f ( x) x 1 and g ( x) x ,
then find the composed rules for g O f and f O g .
g O f ( x) g ( f ( x)) g ( x 1) ( x 1) 2
2 2
f O g ( x) f ( g ( x)) f ( x ) x 1
x 1 x
g O f ( x) g ( f ( x)) g 1 2
f O g ( x) f ( g ( x)) f x 1
2
x2
Ex. Let f : and g :
x g ( x ) sin x
f(x)
2
Determine the domain, codomain, composed rule and
the range of g O f .
f g gO f
Domain of g O f , Codomain of g O f
x
Composed rule : g O f ( x) g ( f ( x)) g
2
x
sin
2
x
For x , sin is either 1, 1 or 0.
2
Range of g O f { 1, 0, 1}
eg. There are 2 electric devices A and B, where A reduces
the voltage by half of its original input and B reduces
the voltage by one third of its original input.
i. What is the composed voltage reduction if a current
first passes through A and then thro ugh B ?
ii. What is the final output if the original voltage is 230v
if A and B are connected as stated in (i) ?
iii. What is the compositio n if A and B are interchang ed
in their connection ? Does this make any difference
to the compositio n in (i) ?
Device A Device B
v v v 2v
v v v v
2 2 3 3
Rule : a (v) v Rule : b(v) 2v
2 3
not 1 1 1 1
This fact is defined as follows.
Definition : A function f : A B is said to be
one - to - one (or injective) if f (a1 ) f (a2 ) then
a1 a2 for every a1 , a2 A .
(equivalen tly, if a1 a2 , then f (a1 ) f (a2 ))
eg. f ( x) 2 x 1 is 1 1.
Let f ( x1 ) f ( x2 )
2 x1 1 2 x2 1
2 x1 2 x2
x1 x2
ie. f ( x1 ) f ( x2 ) x1 x2
f is 1 1.
eg. f ( x) 1 ; x 0 is 1 1.
x
Let f ( x1 ) f ( x2 )
1 1
x1 x2
x1 x2
ie. f ( x1 ) f ( x2 ) x1 x2
f is 1 1.
eg. f ( x) x 2 is not 1 1.
Though f (1) f ( 1) 1 , 1 1.
f is not 1 1.
y x 2
0 X
y x 3
X
0
3 X
0
2 2
1
intersects at
one point.
eg. f ( x) sin x ; 0 x 3 is not 1 1 .
2
3
2
X
0
2
Ex. Check whether the following functions are 1 1
or not using the horizontal line test.
i. f ( x ) x 4 ii. f ( x ) x iii. f ( x ) cos 2 x
iv. f ( x ) tan x ; x
2 2
v. f ( x ) x ; x 0
Onto functions
This is also a special type of functions, where for each
element in the codomain, there is at least one mapping
from the domain.
eg. f :
f ( x) x 1 is onto.
For every y (codomain) , there exists y 1
(domain) such that f ( y 1) y 1 1 y . ie. y is
the image of y 1. So, f is onto.
eg. f :
f ( x) x 1 is not onto.
For 1 (codomain) , there is no any element
in (domain) whose image is 1. So, f is not
onto. Note that f (0) 1, but 0 .
eg. f : 0
f ( x) x 2 is onto.
For every y 0 , there exists y such that
f y y . ie. y is the image of y or y.
So, f is onto.
eg. f :
f ( x) x 2 is not onto.
For 1 (codomain) , there is no any element in
(domain) whose image is 1. So, f is not onto.
Ex. Show that i. f :
f ( x) x 3 is onto.
ii. f : 1, 1
f ( x) sin x is onto.
(Here 1, 1 is the set of real numbers
x that satisfy 1 x 1. Note that if
we put ( 1, 1) , then 1 x 1)
iii. f : 0 , 1 0 ,1
f ( x ) x is not onto.
iv. f : 0 , 2
f ( x ) cos x is not onto.
( Note x 0 , 2 0 x 2)
v. f :
f ( x ) x x is not onto.
Ex. If two functions f : A B and g : B C
are onto, then show that g O f is also onto.
Here , g O f : A C
Want : for every y C , (there exists)
a A s.t. (such that ) g O f (a ) y.
Since g is onto, for every y C , b B
s.t. g (b) y .
But , since f is onto, for every b B , a A
s.t. f (a ) b .
That is , for every y C , a A
s.t. g ( f (a )) y ie. g O f (a ) y .
g O f is onto.
Remark : Horizontal line test to check onto feature.
Codomain
X
values 0
2
1
horizontal lines below
to the x - axis do not
intersect the graph.
eg : f : 0 , 0, 1
f ( x) sin x is onto.
Y
1
Codomain
values
X
0
2
each horizontal line
intersects the graph.
Ex. Check whether the following functions are onto
or not using the horizontal line test.
i. f : Z ii. f : 0 ,1
3
f ( x ) x f ( x ) cos x
iii. f : iv. f :
2
f ( x ) x f ( x ) x
Inverse of a function
Suppose y is the image of x under the rule of a
function f . Then, what is the rule that assigns y to x ?
f
x y
?
This reverse process is called the inversion and the
required function is called the inverse function of f
or simply the inverse of f . Inverse of f is denoted
by f 1.
We can construct the rule of the inverse function
without th inking much about domain and codomain.
x x2 f 1 ( x) x 2
1
f
1
eg. Find f for f ( x) 2 x 1 ?
f
1 x 1
x 2x 1 f ( x)
2
1
f
Note that addition and substracti on are inverses
of each other. Multiplica tion and division are
also inveres of each other. In calculatio ns, rule
of inverse can easily be constructe d by putting
y f ( x) and obtaining x in terms of y .
eg. For f ( x ) 2 x 1 y 2 x 1
2 x y 1
y 1
x
2
1 y 1 1 x 1
Then, f ( y ) or identicall y we have f ( x ) .
2 2
Inverse can be composed with the original function
as follows.
f f 1 1
x f ( x) f ( f ( x)) x
f 1
x f 1 ( x) f f ( f 1 ( x)) x
ie. ( f O f 1 )( x) ( f 1O f )( x) x
eg. f :
3
f ( x) x is a 1 1 correspond ence.
Identity functions
An identity function assigns an element to itself.
Definition : The function f : A A defined by
f (a ) a for every a A is called the identity
function.
It is usually denoted by Ι A or simply by Ι . Thus,
for any a A, we have Ι A (a ) a. (ie. a a)
Now, we can define the inverse of a function precisely.
a b
1
f
eg. f :
f ( x) x 3 . Show that f ( x) is invertible and find f 1 ( x).
f is 1 1
3 3
f ( x1 ) f ( x2 ) x1 x2
3 3
x1 , x2 x1 x2 0
2 2
( x1 x2 ) ( x1 x1 x2 x2 ) 0
0
(for x1 , x2 0)
x1 x2 0
x1 x2
ie. f ( x1 ) f ( x2 ) x1 x2
f is 1 1.
f is onto
1
For every y (codomain ), y 3
(domain) s.t.
1
3
1
f y y . So, y is the image of y 3 .
f is onto.
f 1 rule
3
y x 1
Inverse of f : f :
1
x y 3
1
1
f ( x) x 3
1
1
f ( x ) x 3
Ex. determine whether the following functions are
invertible or not. If it is invertible , then find the
rule of the inverse ( f 1 ( x)).
i. f : ii. f :
f ( x) x 2 f ( x) 1
x
iii. f : iv. 2 2
f : , 1, 1
f ( x) x 2 f ( x) sin x
v. f : 0 , 2, 2
f ( x) 2 cos x
5
Ex. Function f ( x) x 32converts temperatu re into Celsius
9
when x is given by Fahrenheit .
What is the function for opposite conversion ?
Inverse of compositions
1 1 1
If h( x) g ( f ( x)) , then h ( x) f ( g ( x))
1 1 1
ie. ( g O f ) f O g
X Y
y x 2 x y2 y x
(y f(x)) (x f(y)) (y f 1(x))
1
Alternativ ely, graph of f ( x ) can be taken as the
reflection (mirror image) of the graph of f ( x ) over
the line y x.
3 Y
eg. f ( x) x y x 3
1
1 y x
f ( x) x 3
1
y x 3