You are on page 1of 25

Section 4.

4 Functions

CS 130 – Discrete Structures


Function Definitions

• Let S and T be sets. A function f from S to T, f: S  T,


is a subset of S x T where each member of S appears
exactly once as the first component of an ordered pair.
– S is the domain of the function.
– T is the codomain of the function.
• If (s, t) belongs to the function, then t is denoted by
f(s)
– t is the image of s under f
– s is a preimage of t under f
– f is said to map s to t

CS 130 – Discrete Structures 39


Diagrams Representation

• If A and B are finite sets, an arrow diagram shows a function f


from A to B by drawing an arrow from each element in A to
the corresponding element of B

• Two properties must be held in the arrow diagram according


to the definition of function:
– Every element of A has an arrow coming out of it
– No one element of A has two arrows coming out of it that point to
two different elements of B
• Example

CS 130 – Discrete Structures 40


Examples

• Which of the following are functions?


– f: S  T where S = T = {1, 2, 3}, f = {(1,1),(2,3),(2,1)}
– g: Z  N where g(x) = |x| (absolute value of x)
– h: N  N where h(x) = x – 4
– f: R  R where f(x) = 4x – 1
– more examples from the book

• For f: Z  Z where f(x) = x2


– what is the image of –4
– what are the preimages of 9

CS 130 – Discrete Structures 41


Several Common Math Functions

• Floor function
– associates with each real number x the greatest integer
less than or equal to x
– E.g., 2.8 = ?, - 2.8 = ?

• Ceiling function
– associates with each real number x the smallest integer
greater than or equal to x
– E.g, 2.8 = ?, -2.8 = ?

• Modulo function f(x) = x mod n


– associates with x the remainder when x is divided by n
– we can write x = qn+ r, r is between [0, n-1]
– 10 mod 3 = 1

CS 130 – Discrete Structures 42


Functions With Multiple Variables

• A function can include more than one variable.


A function can be defined as
– f: S1  S2 …… Sn  T that associates with each
ordered n-tuple of elements (s1, s2, …, sn)
– Example: f: Z  Z  Z is given by f(x,y) = x+y

CS 130 – Discrete Structures 43


Properties of Functions: Surjective

• Three properties: surjective (onto), injective, bijective

• Let f: S  T be an arbitrary function


– every member of S has an image under f and all the images are
members of T
– the set R of all such images is called the range of the function f

• A function f: S  T is an onto, or surjective, function if the


range of f equals the codomain of f

CS 130 – Discrete Structures 44


Example of Surjective Functions

• To prove a function to be surjective: need to show that


an arbitrary member of the codomain T is a member of
the range R, thus it is the image of some member of the
domain, we have T  R

• To disprove it: if we can find one member of the


codomain that is not the image of any member of the
domain

• Let f: Q  Q where f(x) = 3x + 2


• Let g: Z  N where g(x) = |x|
• Let f: R  R where f(x) = 4x – 1

CS 130 – Discrete Structures 45


Properties of Functions:
Injective, Bijective

• A function f: S  T is an one-to-one or
injective, if no member of T is the image
under f of two distinct elements of S
– To prove a function is injective: we assume that
there are elements s1 and s2 of S with f(s1) = f(s2)
and then show that s1 = s2
– To disprove it: counterexample, where an element in
the range has two preimages in the domain

• A function f: S  T is bijective, if it is both


surjective and injective

CS 130 – Discrete Structures 46


Examples

• The function g: R  R where g(x) = x3


– surjective, injective, bijective

• The function f: N  N where f(x) = x2


– not surjective, injective, not bijective

CS 130 – Discrete Structures 47


In General

CS 130 – Discrete Structures 48


Composition of Functions

• Let f : S  T and g : T  U . Then the


composition function, g  f , is a function
from S to U defined by ( g  f )( s )  g ( f ( s)) .
– Function f is applied first, and then function g
– It is not always possible to take any two arbitrary
functions and compose them since the domain and
the ranges have to be compatible.
– Note that composition preserves the properties of
being onto and being one-to-one
• Composition on two bijections is a bijection

CS 130 – Discrete Structures 49


Examples

• Let f: R  R be defined by f(x) = x2 and g: R  R be


defined by g(x) = x
– What is the value of (g f) (2.3) ?
• g(f(2.3)) = g(5.39) = 5
– What is the value of (f  g) (2.3) ?
• f(g(2.3)) = f(2) = 4
– Order is important in function composition

• The following functions map R to R. Give an equation


describing the composition functions f  g and g  f in
each case:
– f(x) = 3x2, g(x) = 5x

CS 130 – Discrete Structures 50


More Examples

• Given the following function, decide whether it is 1-to-1


or onto:
• f: NN, f(x) = x + 1

but 1-to-1
Proof that f is one-to-one.
Let f(s1) = f(s2) for s1, s2 .
Then
s1 + 1 = s2 + 1 definition of f
s1 = s2 algebra
CS 130 – Discrete Structures f is one-to-one 51
Proofs

• Let f: S  T and g: T  U, and assume that


both f and g are one-to-one (injective)
functions. Prove that g f is a one-to-one
function.

• Let f: S  T and g: T  U be functions


– Prove that if g f is 1-to-1, so is f.
– Prove that if g f is onto, so is g.
– Find an example where g f is 1-to-1, but g is not 1-
to-1.
– Find an example where g f is onto but f is not onto.

CS 130 – Discrete Structures 52


Inverse Functions

• Bijective functions have another property:


– Every element s in S has an image in T and every element
of T has a unique inverse image in S since the f is onto
and one-to-one
• If there is a function f which has a one-to-one
correspondence from a set S to a set T, then there is a
function g from T to S that "undoes" the action of f. This
function g is called the inverse function for f.
• Then g f (s) = s maps each element to itself. Such a
function which leave an element unchanged is called the
identity function on S and is denoted by is
• Show that f  g = iT

CS 130 – Discrete Structures 53


Inverse Functions

• Definition: Let f: S  T. If there exists a


function g: T  S, such that
– g f = iS and f  g = iT
– Then g is called the inverse function of f and is
denoted by f –1

• Example: f: R  R given by f(x) = 3x + 4 is a


bijection. Describe f –1

• Theorem on Bijections and Inverse Functions:


– Let f: S  T. Then f is a bijection if and only if f –1
exists

CS 130 – Discrete Structures 54


More Proofs

• Let f and g be bijections, f: ST and g: TU.


Then f-1 and g-1 exist. Also g f is a bijection
from S to U.

CS 130 – Discrete Structures 55


Summary of Function Terminologies

Term Meaning
function A function f from set S to set T is a relationship between elements of S
and elements of T where each element of S is related to a unique
element of T. It is denoted by f: S  T.
domain Starting set for a function
codomain Ending set for a function
image Point that results from a mapping
preimage Starting point for a mapping
range Collection of all images of a domain
onto (surjective) Range is the whole codomain; every codomain element has a preimage
one-to-one (injective) No two elements in a domain map to the same place
bijection One-to-one and onto
identity function Maps each element of set to itself
inverse function For a bijection, a new function that maps each codomain element back
where it came from

CS 130 – Discrete Structures 56


Exercises

• Let S = {0, 2, 4, 6} and T = {1, 3, 5, 7}.


Determine whether each of the following sets
of ordered pairs is a function with domain S
and codomain T. If so, it is 1-to-1? Is it onto?
a. {(0, 2), (2, 4), (4, 6), (6, 0)}
b. {(6, 3), (2, 1), (0, 3), (4, 5)}
c. {(2, 3), (4, 7), (0, 1), (6, 5)}
d. {(2, 1), (4, 5), (6, 3)}
e. {(6, 1), (0, 3), (4, 1), (0, 7), (2, 5)}

CS 130 – Discrete Structures 57


Exercises

• Which of the following are functions from the domain to the


codomain given? Which functions are 1-to-1 or onto or both?
Describe the inverse function for any bijective function.
a. f: ZN where f(x) = x2 + 1
b. g: NQ where g(x) = 1/x
c. h: Z x N  Q where h(z, n) = z/(n+1)
d. f: {1, 2, 3}  {p, q, r} where f = {(1, q), (2, p), (3, r)}
e. g: NN where g(x) = 2x
f. h: R2  R2 where h(x, y) = (y + 1, x + 1)

CS 130 – Discrete Structures 58


Exercises

• Let P be the power set of {a, b, c}. A function


f: PZ follows: for A in P, f(A) = the number
of elements in A.
– Is f 1-to-1?
– Is f onto?

CS 130 – Discrete Structures 59


Exercises

• Let f: NN be defined by f(x) = x + 1. Let g:


NN be defined by g(x) = 3x. Calculate the
following:
a. (gf)(x)
b. (fg)(x)
c. (ff)(x)
d. (gg)(x)

CS 130 – Discrete Structures 60


Exercises

• The following functions map R to R. Give an


equation describing the composition functions
(gf) and (fg) in each case.
a. f(x) = 6x3, g(x) = 2x
b. f(x) = (x-1)/2, g(x) = 4x3
c. f(x) = x , g(x) = x

CS 130 – Discrete Structures 61


Exercises

• For each of the following bijections f: RR,


and g: R2  R2 find f-1 and g-1.
a. f(x) = 2x
b. f(x) = x3
c. f(x) = (x+4)/3
d. g(x, y) = (2x, y+1)

CS 130 – Discrete Structures 62

You might also like