You are on page 1of 49

Functions!

1
A Bit Of Terminology
Relation R on sets A and B: R (A B)
Not all elements of A or B need be in R
So there are four sets that we need to be concerned
about:
A Source set
B Target set
The part of A actually used in R Domain
The part of B actually used in R Range

These definitions are not universally agreed


2
Functions
A function is a special kind of relation
Each item in the domain maps to one item in
the range
Pre Image Image
Example: Target Set
Source Set

Domain Range
3
Example Functions
NOTE

A pre-image The image


Domain Target of A of A
Alice A a 1
Bob B bb 2
Chris C cccc 3
Dave D dd 4
Emma F e 5

A class grade function A string length function

4
FunctionsPoints To Note
Some items of the source set might not be mapped, i.e., not in
the domain
Some items of the target set might not be the object of a
mapping, i.e., not in the range
Multiple items of the domain might map to the same item in the
range
A basic subprogram structure in programming languages is the
function

5
Partial And Total Functions
A function is total if mapping is defined for all
items in the source set, i.e., domain=source set
A function is partial if mapping is defined for
some (possibly all) items in the source set

TOTAL PARTIAL
FUNCTION FUNCTION 6
Functions
Function? Why or why not? Total vs Partial?
a. f(x), where x is a student in your class, is the number of instances
of the letter e in xs last name.
b. f(x), where x is a student in a given class, is the student in the class
who comes next after x in alphabetical order by last name.
c. f(x), where x is a bit string, is the number of bits in the string.
d. f(x), where x is an integer, is the last digit of x.
e. f(x), where x is a positive integer, is the next smallest integer.
f. f(x), where x is a bit string, is the position of the first (least
significant) 1 in the bit string.
g. f(x), where x is a person, is the last four digits of xs phone number.

7
8
Identity Function
Given a set , define a function by
(sometimes denoted ) is called the identity
function because it doesnt alter the input in
anyway. Or in other words the output is
identical to the input.

9
Injective Functions
A (partial or total) function is injective if its
inverse is also a function: Notice:
Injective & Inverse
Also called One-to-One functions

INJECTIVE NON-INJECTIVE
FUNCTION FUNCTION 10
One to One
a1A a2A (f (a1) = f(a2)) (a1 = a2)

11
How to Prove 1-1?
Suppose
that is a function defined on a set to a set ,
written as . To show that is 1-1 we need to prove
the following statement is true.

Most of the time we will use a direct proof, that is


assume with and show that .
Does this remind you of another proof technique?

12
How to disprove 1-1?
A function is one-one if the following is true.

What is the negation of this statement?

Therefore we can show that something is not 1-1 if


we can find two elements in the domain that map to
the same element in the range.

13
Proving that a function is 1-1
Let where

Is 1-1?
Remember a function, is 1-1 if the following
is true:

14
15
Proving that a function is 1-1
Let such that

Is 1-1?

16
Surjective Functions
A (partial or total) function is surjective if
domain maps to all of target set:
Also called Onto functions

SURJECTIVE NON-SURJECTIVE
FUNCTION FUNCTION
17
Onto
bB aA (f(a) = b)

18
How to prove Onto
The definition of onto is given by then:

Therefore we pick an arbitrary and show that


there exists an such that
This is usually shown with a direct proof.

19
How to disprove Onto
The definition of onto is

What is the negation of this statement?

This means we find a such that all do not


map onto .
This is usually proved using proof by
contradiction.
20
Proving that a function is Onto
Let where

Is Onto?
Remember that a function, , is onto if the
following is true:

21
22
Proving that a function is Onto
Let such that

Is Onto?

23
Bijective Functions
A (partial or total) function is bijective if it is
injective and surjective:
Also referred to as One-to-One correspondence

TOTAL PARTIAL
BIJECTIVE FUNCTION BIJECTIVE FUNCTION
24
1-1 Correspondence
Let where

Is a 1-1 correspondence?
Let such that

Is a 1-1 correspondence?

25
Inverse: f -1

f = { (a1, b1), (a2, b4), f -1 = { (b1, a1), (b2, a3),


(a3, b2), (a4, b3)}
a1 b1
(b3, a4), (b4, a2)}
a2 b2
a3 b3
a4 b4
f -1

one-to-one correspondence
26
Compositions Of Functions
There Is A Rule Here
Isnt There?
Definition: (f g)(x) = f(g(x))

Let f(x) = 2x+3 Let g(x) = 3x+2

g(1) = 5, f(5) = 13

Thus, (f g)(1) = f(g(1)) = f(5) = 13

27
Compositions Of Functions
fg
A B C
g f

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

(f g)(a)

28
Compositions Of Functions
Let f(x) = 2x+3 Let g(x) = 3x+2
fg
R R R
g f

g(1) f(5)
f(g(1))=13
1
g(1)=5

(f g)(1)
f(g(x)) = 2(3x+2)+3 = 6x+7
29
Compositions Of Functions
Does f(g(x)) = g(f(x))?

Let f(x) = 2x+3 Let g(x) = 3x+2

f(g(x)) = 2(3x+2)+3 = 6x+7


g(f(x)) = 3(2x+3)+2 = 6x+11 Not equal!

Function composition is not commutative!

30
Composition, 1-1 and Onto
Suppose f: A B and g: B C.
(a) Prove that if g f is onto then g is onto.

(b) Prove that if g f is one-to-one then f is one-to-


one.

31
The Identity function is a 1-1
Correspondence
Given any set let be the identity function
for . Prove that is a 1-1 correspondence.

Suppose that is a function from for and is a


function from to such that and , then .

32
Finding the inverse of a Function
Consider the function such that .
Is this function invertible?
No? Why not?
What about the following function such that
We have that , why is this not sufficient to show that
?

33
Functions Acting on Sets
Definition: If and and , then:

is called the image of , and is called the


inverse image (or pre-image) of C.

34
Example The Action of a Function on Subsets of a Set

Let X = {1, 2, 3, 4} and Y = {a, b, c, d, e}, and


define
F : X Y by the following arrow diagram:
Let A = {1, 4}, C = {a, b}, and D = {c, e}.
Find F(A), F(X), F1(C), and F1(D).
Set Properties and Functions
Let with and .
Prove or disprove the following:

36
37
Cardinality and Functions
Let f be a function from A to B that is 1-1 and onto.
Show that if A and B are finite sets then |A| = |B|.

a1 ba1
f one-to-one a2 ba2 |B| |A|
...
an ban
Thus, |A| = |B|.

a1 ba1
f onto |A| |B|
a2 ba2
...
an ban 38
Countable Sets

The set Z+ of counting numbers {1, 2, 3, 4, . . .} is, in a


sense, the most basic of all infinite sets.
Definition: A set A having the same cardinality as this set is
called countably infinite.
The reason is that the one-to-one correspondence between
the two sets can be used to count the elements of A: If F is
a one-to-one and onto function from Z+ to A, then F(1) can be
designated as the first element of A, F(2) as the second
element of A, F(3) as the third element of A, and so forth.
Countable Sets
This is illustrated graphically in the following figure

Counting a Countably Infinite


Set

Because F is one-to-one, no element is ever counted twice,


and because it is onto, every element of A is counted
eventually.
Countable Sets
Definition: A set is countably infinite if and
only if it has the same cardinality as the set .
A set is called countable if and only if it is
finite or is countably infinite.
A set that is not countable is called
uncountable.

41
Problem: How can a new guest be accommodated
in a full infinite hotel? (n) = n+1
Problem: How can an infinity of new guests be
accommodated in a full infinite hotel?
(n) = 2n


Problem: How can an infinity of infinities of new
guests be accommodated in a full infinite hotel?


15

14 10 one-to-one
13 9 6 correspondence
12 8 5 3
11 7 4 2 1
Problem: Are there more integers than positive integers?

+
+ -4 -3 -2 -1 0 1 2 3 4
So | + |<|| ?
Rearrangement:
Establishes 1-1
correspondence
: +
+ 1 2 3 4 5 6 7 8 9
| + |=||
Problem: Are there more rationals than positive integers?
7 7 7 7 7 7 7 7

+ 7 1 2 3 4 5 6 7 8
+ 6 6 6 6 6 6 6 556
6 1 2 3 4 5 6 7 8
So | + |<|
| ? 517 518 519 520 215 5 5 5
5 1 2 3 4 5 6 7 8
16 15 14
Dovetailing: 4 4 4 134 224 4 4 4
4 1 2 3 4 5 6 7 8
Establishes 1-1
correspondence 3 3 5 3 6 73 123 233 283 3 3
: + 1 2 3 4 5 6 7 8
24 32 82 112 242 272 2 2
| + |=|| 2 1 2 3 4 5 6 7 8
11 21 91 101 251 261 1 1
1 1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
Problem: Are there more rationals than positive integers?
7 24 7 25 726 7 27 7 28 7 29 7 397
+ 7 1 2 3 4 5 6 7 8
+ 623 6 6 6 22 6 6 30 6 6
6 1 2 3 4 5 6 7 8 s !
So | + |<|
512 513 514 515 5 215 315 385 a te
| ? 5 1 2 3 4 5 6 7 li8c
Dovetailing: 411 4 104 4 164 u p
4 324
Establishes 1-1
4 1 2 3 4
g5d 6 7
4
8
correspondence 3 34 di n
3 5 3 9 3 173 3 333 373
: + 1 2 o i3 4 5 6 7 8
23 Av 2 62 2 182 2 342 2
| + |=|| 2 1 2 3 4 5 6 7 8
11 21 71 8 1 191 201 351 361
1 1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
Theorem: There are more reals than rationals / integers.
Proof [Cantor]: Assume a 1-1 correspondence : +
i.e., there exists a table containing all of and all of :
+ Di
(1) = 3 . 1 4 ag1 5 9 2 6 5 3 f!
o
(2) = 1 . 0 0 0 n0a 0 0 0 0 0 o
ro
(3) = 2 . 7 1 8 2 liz8 1 8 2 8 p
a
(4) = 1 . 4 1 4 2 1 ti3 5 6n 2 c e
(5) = 0 . 3 3 3 3 3 3 n3ste3 3
o
x i
... ...
-e
X = 0 . 2 1 9 3 o4n ...
But X is missing from ourN table! X (k)k +
not a 1-1 correspondence
contradiction
is not countable!
There are more reals than rationals / integers!
Problem 1: Why not just insert X into the table?
Problem 2: What if X=0.999 but 1.000 is already in table?

+ Di
(1) = 3 . 1 4 ag1 5 9 2 6 5 3 f!
o
1 . 0 0 0 n0a 0 0 0 0 0 o
(2) =
ro
(3) = 2 . 7 1 8 2 liz8 1 8 2 8 p
(4) = a
1 . 4 1 4 2 1 ti3 5 6n 2 c e
(5) = 0 . 3 3 3 3 3 3 n3ste3 3
o
x i
... ...
-e
X = 0 . 2 1 9 3 o4n ...
Table with X inserted N will have X still missing!
Inserting X (or any number of Xs) will not help!
To enforce unique table values, we can avoid
using 9s and 0s in X.

You might also like