Functions
Functions
Functions
1
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 xA.
2
Graphical Representations
• Functions can be represented graphically in
several ways:
f A B
• •
f • •
a• • • y
b •
•
• •
x
A
B
3
Some Function Terminology
• If f:A→B, and f(a)=b (where aA & bB),
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, or image,of f is the set of all
images of elements of A.
4
Range vs. Codomain - Example
• Suppose that: “f is a function mapping
students in this class s {A,B,C,D,E}. to the
set of marks {21,22,23,24,25}.”
• At this point, you know f’s domain is:
__________, and its codomain is
{A,B,C,D,E}
{21,22,23,24,25}.
• Now if f(A)=21, f(B)=22, f(C)=21,
f(D)=22, f(E)=25 then range is {21,22,25}.
5
Range vs. Codomain - Example
• Let f : Z → Z assign the double of an
integer to this integer. Then, f (x) = 2x
• The domain of f is the set of all integers, the
codomain of f is the set of all integers, and
the range of f is the set of all integers that
are even, namely, {. . . , -4, -2, 0, 2, 4, . . . }.
6
Function Addition/Multiplication
• A function is called real-valued if its codomain is
the set of real numbers, and
• it is called integer-valued if its codomain is the
set of integers.
• Two real-valued functions or two integer valued
functions with the same domain can be added, as
well as multiplied.
7
Function Addition/Multiplication
• Let f1 and f2 be functions from A to R.
• Then f1 + f2 and f1f2 are also functions
from A to R defined for all x ∈ A by
• (f1 + f2)(x) = f1(x) + f2(x),
• (f1f2)(x) = f1(x)f2(x).
8
Example
• 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?
9
Image of a subset of domain
10
Example
• Let A = {a, b, c, d, e} and B = {1, 2, 3, 4} with
f (a) = 2, f (b) = 1, f (c) = 4, f (d) = 1, and f (e)
= 1.
• The image of the subset S = {b, c, d} is the
set f (S) = {1, 4}.
11
One-to-One Functions
• A function f is said to be one-to-one, or an
injunction, if and only if f (a) = f (b) implies that a
= b for all a and b in the domain of f.
• A function is said to be injective if it is one-to-one.
12
One-to-One Functions
• A function is one-to-one iff every element
of its range has only one pre-image.
– Domain & range have same cardinality.
13
One-to-One Illustration
• Graph representations of functions that are
(or not) one-to-one:
• • • •
• • •
• • •
• • •
• • • •
• • •
• • • •
• • •
Not one-to-one Not even a
One-to-one function!
14
Example
• Determine whether the function f (x) = x2 from the
set of integers to the set of integers is one-to-one.
• Note that the function f (x) = x2 with its domain
restricted to Z+ is one-to-one.
15
Example
• Determine whether the function f (x) = x + 1 from
the set of real numbers to itself is one-to one.
• Solution: The function f (x) = x + 1 is a one-to-one
function. To demonstrate this, note that
“x is injective” : ( x,y: (f(x)=f(y)) → (x =y))
So if x + 1 = y + 1 then x = y.
16
Sufficient Conditions for 1-1ness
• Definitions (for functions f over numbers):
– f is strictly (or monotonically) increasing iff
x>y → f(x)>f(y) for all x,y in domain;
– f is strictly (or monotonically) decreasing iff
x>y → f(x)<f(y) for all x,y in domain;
• If f is either strictly increasing or strictly
decreasing, then f is one-to-one.
– e.g. f(x)=x3
17
Onto (Surjective) Functions
• A function f from A to B is called onto, or a
surjection, if and only if for every element
b ∈ B there is an element a ∈ A with f (a) =
b. A function f is called surjective if it is
onto.
• A function f:A→B is onto iff its range is
equal to its codomain
18
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
19
Example
for domain & codomain R, x3 is onto, whereas x2
isn’t. (Why not?)
20
Bijections
• The function f is a one-to-one
correspondence, or a bijection, if it is both
one-to-one and onto. We also say that such a
function is bijective.
21
Inverse of a 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 b belonging to B the
unique element a in A such that f (a) = b.
• The inverse function of f is denoted by f −1.
Hence, f −1(b) = a when f (a) = b.
22
Inverse of a Function
• 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.
23
Inverse of a function (cont’d)
24
Function Composition
• 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
composition of the functions f and g, denoted for
all a ∈ A by f ◦ g, is defined by
• (f ◦ g)(a) = f (g(a)).
• The range of g must be a subset of f’s domain. (Note
that f ◦ g is not defined, if the range of g is not a subset of
the domain of f.)
• the commutative law does not hold for the composition of
functions. (In general, f○g g○f.)
25
Function Composition
26
Example
• Let f and g be the functions from the set of
integers to the set of integers defined by f
(x) = 2x + 3 and g(x) = 3x + 2. What is the
composition of f and g? What is the
composition of g and f ?
27
The Identity Function
• For any domain A, the identity function
I:A→A (variously written, IA, 1, 1A) is the
unique function such that aA: I(a)=a.
• Some identity functions you’ve seen:
– ing with T, ing with F, ing with , ing
with U.
• Note that the identity function is both one-
to-one and onto (bijective).
28