0% found this document useful (0 votes)
27 views61 pages

Math 2151 Relations and Functions-13

Uploaded by

jacketforsales
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views61 pages

Math 2151 Relations and Functions-13

Uploaded by

jacketforsales
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 61

Relations and Functions

Math 2151: Discrete Math for Engineering

University of Western Ontario


Fall 2024

Diego Manco (he/him, from Colombia) Office MC 134


e-mail: [email protected]
Office hours: Mon 4:30-5:30pm, Tu 2-3pm, and Wed 2:30-3:30pm.
Relations

Relations are subsets of cartesian products, that is, collections of


ordered pairs.
Definition
A set R is said to be a relation relating elements of A to elements
of B if R ⊆ A × B.
Sometimes people write xRy instead of ( x, y) ∈ R.

Relations are similar to sets in some sense, for example, they are
equal if they have the same ordered pairs.
Theorem
Two relations R1 , R2 are equal if and only if

∀ x∀ y(( x, y) ∈ R1 ↔ ( x, y) ∈ R2 )

Math 2151: Discrete Math for Engineering Relations and Functions


Examples
In R × R we have the relation
≤= {( x, y) : x ≤ y}
For example (1, 2) ∈≤ but (2, 1) ∈≤/
In Z × Z we have the divisibility relation | :
| = {( a, b) : ∃k ∈ Z(b = ka)}
We write a|b to mean ( a, b) ∈ |.
Let A be a set. In P ( A) × P ( A) we have the relation ⊆ A .
⊆ A = {( B, C ) : B ⊆ A ∧ C ⊆ A ∧ B ⊆ C }
We can get less meaningful relations that still are sets of
ordered pairs, for example
R = {( x, y) ∈ R2 : y = x2 },
S = {( x, y) ∈ R2 : x2 + y2 > 0}.
R is the graph of the parabola y = x2 , while
S = R2 \ {(0, 0)}.
Math 2151: Discrete Math for Engineering Relations and Functions
Symmetric relations
Definition
 
A relation R ⊆ A × B is called reflexive if ∀ x ∈ A ( x, x) ∈ R

In R × R the relation is symmetric since for x ∈ R ,x ≤ x.


In Z × Z divisibility relation | :
| = {( a, b) : ∃k ∈ Z(b = ka)}
is symmetric since a = 1 × a, and so a| a for any a ∈ Z.
In P ( A) × P ( A) the relation ⊆ A is reflexive since for B ⊆ A,
B ⊆ B.
For R, S as subsets of R × R
R = {( x, y) ∈ R2 : y = x2 },
S = {( x, y) ∈ R2 : x2 + y2 > 0}.
We have that R is not symmetric since (2, 2) ∈ / R. Notice
that (1, 1) and (0, 0) are the only pairs of the form ( x, x)
which belong to R, why?S is not symmetric since (0, 0) ∈ / S.
Math 2151: Discrete Math for Engineering Relations and Functions
Reflexive relations

Definition
A relation R ⊆ A × A is said to be symmetric if for all a, b ∈ A

( a, b) ∈ R → (b, a) ∈ R.

Math 2151: Discrete Math for Engineering Relations and Functions


This time we will practice with finite relations, but from the
relations of the previous pages the only one that is symmetric is S.
≤, ⊆ A , |, and R are all not symmetric. Why?
Consider now A = {1, 2, 3} and the following relations
R1 = {(1, 2), (2, 1), (2, 3), (3, 2)}
R2 = {(1, 1), (2, 2), (3, 3), (1, 2)}
R3 = {(1, 1), (1, 2), (2, 2)}
R4 = {(1, 1), (2, 2), (3, 3), (1, 3), (3, 1)}
R1 is symmetric, but not reflexive.
R2 is reflexive, but not symmetric.
R3 is not reflexive nor symmetric.
R4 is both reflexive and symmetric.
Can you count the number of relations R ⊆ A × B given
| A| = m and | B| = n?Answer: 2mn
In the same context. Can you count the relations R ⊆ A × B
that are reflexive? What about the relations R ⊆ A × Athat
are symmetric and reflexive?
Math 2151: Discrete Math for Engineering Relations and Functions
Definition
A binary relation on A, R ⊆ A × A, is transitive iff for all
x, y, z ∈ A

( x, y) ∈ R ∧ ( y, z) ∈ R → ( x, z) ∈ R.

The relations ≤⊆ R × R, ⊆ A ⊆ P ( A) × P ( A), and


| ⊆ Z × Z are all transitive.
Consider the relation
S = {( x, y) ∈ R × R : xy ≥ 0}
(x, y have the same sign or one is zero). We have that
xx = x2 ≥ 0, so the relation is reflexive. xy = yx, so the
relation is symmetric. However, the relation is not transitive
since (1, 0) ∈ S, (0, −1) ∈ S, but (1, −1) ∈ /S
Finite example of a transitive relation A = {0, 1, 2}
R = {(0, 0), (2, 2), (1, 2), (2, 0), (1, 0)}.
Finite example of a non transitive relation A = {0, 1, 2}
R = {(0, 0), (2, 2), (1, 2), (2, 0)}.
Math 2151: Discrete Math for Engineering Relations and Functions
Antisymmetry, Partial Orders
Definition
A relation A ⊆ A × A is said to be antisymmetric if for all
x, y, z ∈ A
(( x, y) ∈ R ∧ ( y, x) ∈ R) → x = y
A relation R ⊆ A × A is said to be a partial order on A if R is
reflexive, transitive, and antisymmetric. In that case we also say
that ( A, R) is a partially order set (poset).

(R, ≤), and (P ( A), ⊆ A ), are partially ordered sets. (Z, |) is


not a partially ordered set since | is not antisymmetric. This is
because x| − x for every integer x. For example: 2| − 2 and
−2|2.
Let A = {1, 2}. We have that the relation
R = {(1, 2), (2, 1)} is not antisymmetric since 1 ̸= 2. It is
also not transitive. S = {(1, 1), (2, 2), (1, 2)} is reflexive,
transitive and antisymmetric. So ( A, S) is a partially ordered
set.
Math 2151: Discrete Math for Engineering Relations and Functions
Total orders

Definition
Let R ⊆ A × A be a partial order. Two elements a, b ∈ A are
comparable if
( a, b) ∈ R ∨ (b, a) ∈ R
We say that R ⊆ A × A is a total order if in adition to being a
partial order, every two elements in A are comparable. That is,
∀ a ∈ A∀b ∈ A(( a, b) ∈ R ∨ (b, a) ∈ R)

(P ({0}), ⊆) is a total order. However, (P ({0, 1}), ⊆) is not


since {0} and {1} are not comparable.
(R, ≤) is a total order.
(Z, |) is not a total order. For example 2 and 3 are not
comparable.

Math 2151: Discrete Math for Engineering Relations and Functions


Hesse diagrams

Definition
A Hesse diagram of a partial order R ⊆ A × A consists of:
a vertex (a node which might join lines) for each element of
A.
if aRb, then b is position higher than a.
if aRb and there is not a c different from a and b s.t. aRc and
cRb, then a line conects a and b.

Math 2151: Discrete Math for Engineering Relations and Functions


Hesse diagram for P ({ a, b, c}, ⊆)

{ a, b, c}

{ a, b} { a, c} {b, c}

{ a} {b} {c}

Math 2151: Discrete Math for Engineering Relations and Functions


Hesse diagram for {(0, 0), (0, 1), (0, 2), (1, 1), (1, 2), (2, 2)}

Math 2151: Discrete Math for Engineering Relations and Functions


It’s easier to put examples of partial orders via Hesse Diagrams.
Definition
An element a ∈ A, where ( A, R) is a poset is said to be a maximal
element iff
∀ x ∈ a( aRx → a = x).
An element a ∈ A where ( A, R) is a poset is said to be the
maximum of the poset if ∀ x ∈ A( x ≤ a).
Similarly for minimal, minimum.

One difference between maximal and maximum is that every


element has to be comparable to the maximum, however not every
element has to be comparable with a maximal.

Math 2151: Discrete Math for Engineering Relations and Functions


Example maximum, minimum

c f

d b e

a h

Find all maximal and minimal elements as well as minimum and


maximum if they exist.
Here, c and k are maximal elements while g is a minimum. There
is no maximum.
Math 2151: Discrete Math for Engineering Relations and Functions
Lowest upper bounds

Definition
Let ( P, ≤) be a partially ordered set. Let A be a subset of P. An
upper bound of A is an element u ∈ A s.t.

a≤u

for all a ∈ A. An upper bound A is called the lowest upper bound


of A, if it is the minimum among upper bounds of A. That is, if

∀ a ∈ A( a ≤ u′ )) → u ≤ u′

(u′ upper bound implies u ≤ u′ ). When it exists, the lowest upper


bound of A is unique and we call it lub( A). It can be the case
that a lub( A) doesn’t exist.
For a, b ∈ A, the lub({ a, b}) is called a ∨ b.

Math 2151: Discrete Math for Engineering Relations and Functions


Greatest lower bounds
In this page we define the dual concept to (lowest) upper bound
which is that of (greatest) lower bound. You just have to change
the ≤ in the previous page by ≥ .
Definition
Let ( P, ≤) be a partially ordered set. Let A be a subset of P. A
lower bound of A is an element l ∈ A s.t.

l≤a

for all a ∈ A. A lower bound A is called the greatest lower bound


of A, if it is the maximum among lower bounds of A. That is, if

∀ a ∈ A(u′ ≤ a)) → u′ ≤ u

(u′ lower bound implies u′ ≤ u). When it exists, the greatest lower
bound of A is unique and we call it glb( A). glb( A) may not exist.
For a, b ∈ A, the glb({ a, b}) is called a ∧ b.
Math 2151: Discrete Math for Engineering Relations and Functions
Example: finding some lub’s in
Consider the previous Hesse diagram
k

c f

d b e

a h

g
We have the following: lub{b, e} = b ∨ e = c, but also
lub{ a, h} = a ∨ h = c (c is the only upper bound of {e, h}).
Somme lub’s that don’t exist are lub{c, f } (there are no upper
bounds of {c, f })
Math 2151: Discrete Math for Engineering Relations and Functions
More examples of lub’s

f g

d e

a b c
In this partially ordered set lub{ a, b} = a ∨ b doesn’t exist. The
upper bounds of { a, b} are d, e. But the set {d, e} doesn’t have a
minimum since d and e are not comparable.
Now, lub{b, c} = e. Let’s see why. {b, c} has upper bounds e, f , g.
And the minimum of the upper bounds is e.

Math 2151: Discrete Math for Engineering Relations and Functions


Equivalence relations
Equivalence relations are other type of relations that aim at
classifying some type of objects by dividing them into bunches that
are equivalent among them.
Definition
A relation ∼⊆ A × A is called an equivalence relation if the
relation is reflexive, symmetric and transitive. That is, if for
a, b ∈ A
a∼a
If a ∼ b, then b ∼ a.
If a ∼ b and b ∼ c, then a ∼ c

You shouldn’t think of an equivalence relation as an order relation.


An equivalence relation doesn’t order objects. It classifies them
into equivalent bunches. These bunches are called equivalent
classes.

Math 2151: Discrete Math for Engineering Relations and Functions


Some typical examples

Let A be the set of statements on letters a, b, . . . , z. Then


consider the relation ⇔⊆ A × A. That is, p, q ∈⇔ if and
only if p ⇔ q. This is an equivalence relation.
Let k ̸= 0 be an integer and consider the relation ∼k ⊆ Z × Z
where m ∼ n if and only if k|(m − n) (k divides m − n). This
is an example of an equivalent relation.
Consider the set F of products offered at FreshCo today.
Consider the relation R ⊆ F × F s.t. pRq if and only if p and
q have the same price today.
Consider the set of people born in Ontario O, and the relation
R ⊆ O × O where xRy if and only if x and R where born in
the same municipality. Then R is an equivalence relation.

Math 2151: Discrete Math for Engineering Relations and Functions


Non examples, Equivalence classes

Most examples of order relations are not examples of equivalence


relations since they violate symmetry. For example, (R, ≤),
(P ( A), ⊆), (Z, |) are not equivalence relations.
Definition
Given R ⊆ A × A an equivalence relation and a ∈ A. The set of
elements equivalent to a is usually denoted by

[ a] = {b ∈ A : aRb}.

In the book they denote [ a] = ā. The quotient A/ R is the set of


equivalence classes

A/ R = {[ a] : a ∈ A}

Math 2151: Discrete Math for Engineering Relations and Functions


Main example

Our main example of an equivalence relation is the relation


∼k ⊆ Z × Z for k ̸= 0 an integer.
For k = 2, we have a ∼ b if and only if 2|( a − b). We have two
equivalence classes:

[0] = {· · · , −4, −2, 0, 2, 4, · · · } = {2n : n ∈ Z} = 2Z,

and

[1] = {· · · , −5, −3, −1, 1, 3, 5, · · · } = {2n + 1 : n ∈ Z} = 2Z + 1

Z/ ∼2 = {2Z, 2Z + 1} is the quotient, that is, the set of


equivalence classes.

Math 2151: Discrete Math for Engineering Relations and Functions


Main example

In general, for ∼k ⊆ Z × Z for k ̸= 0 an integer. We have k


equivalence classes:

kZ, kZ + 1, kZ + 2, . . . , kZ + (k − 1)

With quotient Z/ ∼k = {kZ, kZ + 1, . . . , kZ + (k − 1)}.

Math 2151: Discrete Math for Engineering Relations and Functions


Weird example
Let’s try to exemplify the idea that giving an equivalence relation
on a set is the same as classifying the elements of the set into
equivalent bunches.
Suppose that our set is the numbers between 0 and 2 in the real
line [0, 2). We can express this set as a union of sets that do not
intersect in many different ways, but here is one:

[0, 2) = [0, 1) ∪ [1, 2)

Let’s say we want the sets on the right hand side to be the
equivalence classes. That is, we want all elements in [0, 1) to be
equivalent, and all elements in [1, 2) to be equivalent as well. We
can declare that a ∼ b if and only if
   
a, b ∈ [0, 1) ∨ a, b ∈ [1, 2) .

We get an equivalence relation from this.


Math 2151: Discrete Math for Engineering Relations and Functions
The previous examples wasn’t actually weird

Lemma
Let ∼⊆ A × A be an equivalence relation. Then:
If a ∈ A, then [ x] = [ a] if and only if x ∼ a.
a ∈ [ a] (the union of all equivalence classes is A)
If a, b ∈ A, and [ a] ∩ [b] ̸= ∅, then [ a] = [b]. (The
equivalence classes are mutually disjoint)

Definition
Let A be a set. A partition is a set P ⊆ P ( A) s.t.
For every a ∈ A there is a p ∈ P s.t. a ∈ p. (The union of the
elements of P is the whole A)
For a, b ∈ P, if a ∩ b ̸= ∅, then a = b. (The elements of P are
mutually disjoint).

Math 2151: Discrete Math for Engineering Relations and Functions


Equivalence relations = partitions

What I mean is that every equivalence relation gives a partition,


and every partition gives an equivalence relation.
Equivalence relation vs partitions
Given an equivalence relation ∼⊆ A × A, the previous pages give
us that A/ ∼ is a partition of A.
In the other direction, given a partition P ⊆ P ( A), we can define
a equivalence relation ∼ P ⊆ A × A by declaring that

a ∼ p b ⇔ ∃ p ∈ P( a ∈ p ∧ b ∈ p)

So, equivalence relations are the same as partitions. In the exercise


you will be asked about the partition given by an equivalence
relation or the equivalence relation given by a partition. This is
what they mean.

Math 2151: Discrete Math for Engineering Relations and Functions


More examples
Now we can easily construct examples of equivalence relations.
Consider the real line. The following is a partition of the real
line
P = {[n, n + 1) : n ∈ Z}
So, we get an equivalence relation in the real line by declaring
that
 
a ∼ b ⇔ ∃n ∈ Z ( a ∈ [n, n + 1) ∧ b ∈ [n, n + 1) .

How many equivalence relations ∼⊆ A × A where


A = {0, 1, 2, 3, 4} are there s.t. 2 ∼ 4 and 0 ∼ 3.We have to
have a bunch containing {{2, 4} and a bunch containing
{0, 3}. Since 1 is the only element not in a bunch yet we have
three possible partitions (and so, the answer is 3):
P = {{{2, 4}, {0, 3}, {1}}. (1 is its own bunch).
P = {{{2, 4, 1}, {0, 3}} 1 is bunched together with 2 and 4.
P = {{{2, 4, 1}, {0, 3, 1}} 1 is bunched together with 0 and 3.
Math 2151: Discrete Math for Engineering Relations and Functions
Functions

Definition
Let A, B be sets. A function f : A → B is f ⊆ A × B such that

∀ a ∈ A∃!b ∈ B(( a, b) ∈ f ).

(That is: for every a ∈ A there is a unique b ∈ B s.t. ( a, b) ∈ f ).


When a ∈ A and f : A → B is a function we call the unique b s.t.
( a, b) ∈ f , f ( a).
This means two things:
( a, f ( a)) ∈ f
( a, b) ∈ f implies b = f ( a)

Math 2151: Discrete Math for Engineering Relations and Functions


Many examples

There are many functions f : {0, 1, 2} → {3, 4, 5} one such


functions is
f = {(0, 3), (1, 4), (3, 5)}.

Examples of an f ⊆ {0, 1, 2} × {3, 4, 5} that are not a


functions
f 1 = {(0, 3), (2, 4)},
f 2 = {(0, 3), (1, 3), (1, 4), (2, 5)},
why?
How many functions f : {0, 1, 2, 3} → {3, 4, 5} are there?34
You have to make four choices, f (0), f (1), f (2), and f (3).
For each choice you have three options
There are mn functions from {1, 2, . . . , n} to {1, 2, . . . , m}.

Math 2151: Discrete Math for Engineering Relations and Functions


Infinite domain functions. When f : A → B and A is not
finite, functions are often described using a formula. Examples
of this are f : R → R given by f ( x) = x2 − 1 or
g : (0, ∞) → R given by g( x) = ln( x). For us, these
functions ARE their graphs, that is,

f = {( x, x2 − 1) ∈ R × R : x ∈ R},

and
g = {( x, ln( x)) ∈ R × R : x ∈ R}

Math 2151: Discrete Math for Engineering Relations and Functions


Injective, one-to-one, onto, range
Definition
A function f : A → B is called injective if for x, y ∈ A

f ( x) = f ( y) → x = y,

A function f : A → B is called surjective if for all b ∈ B, there


is a preimage a ∈ A s.t. f ( a) = b.
A function is f : A → B is called bijective if it is both
injective and surjective.
We say that A and B have the same number of elements or
the same cardinality when there’s a bijective function
f : A → B. We write this as A ≈ B
When f : A → B A is called the domain of f dom( f ) and the
range of f is defined as

ran( f ) = { f ( a) : a ∈ A}

Math 2151: Discrete Math for Engineering Relations and Functions


Finite examples

Onto function f : {0, 1, 2} → {0, 1} given by


f = {(0, 0), (1, 1), (2, 1)} is onto because f (0) = 0,
f (1) = 1 so every element in {0, 1} ”gets hit”. This function
is not injective since f (1) = f (2) = 1. In fact no function
f : {0, 1, 2} → {0, 1} can be injective.
Can there be an onto function f : {0, 1, 2} → {0, 1, 3, 4}?
Anser: no!
f : {0, 1, 2} → {0, 1, 2, 3, 4} with f = {(0, 1), (1, 2), (2, 4)}
is injective. There are no bijective functions
f : {0, 1, 2} → {0, 1, 2, 3, 4}, why?
Let’s count the number of injective functions
f : {1, 2, 3} → {1, 2, 3, 4, 5}. Answer: 5 × 4 × 3.

Math 2151: Discrete Math for Engineering Relations and Functions


Inclusion-exclusion principle

Counting the number of onto functions f : A → B where | A| = m


and | B| = n is hard. But it gets a little bit easier if we introduce
the following counting principle.
Theorem
Inclusion-exclusion principle Let A1 , . . . , An be finite sets. Then
n
[ n
Ai = ∑ | Ai | − ∑ | Ai ∩ A j | + ∑ | Ai ∩ A j ∩ Ak |−
i =1 i =1 1 ⩽i < j ⩽ n 1 ⩽i < j < k ⩽ n

− · · · + (−1)n+1 | A1 ∩ · · · ∩ An |

For n = 3 this takes the form:

| A ∪ B ∪ C | = | A| + | B| + |C | − | A ∩ B| − | A ∩ C | − | B ∩ C | + | A ∩ B ∩ C |

Math 2151: Discrete Math for Engineering Relations and Functions


Counting onto functions
Let’s count the number of onto functions
f : {1, 2, 3, 4} → {1, 2, 3}. Remember that a function is not onto
if it doesn’t hit 1,2 or 3.
We can thus express the set of onto functions

F = { f : {1, 2, 3, 4} → {1, 2, 3} : f is not onto }

as the union F = F1 ∪ F2 ∪ F3 where

Fi = { f : {1, 2, 3, 4} → {1, 2, 3} : i ∈
/ ran f }

We have that

| F | = | F1 ∪ F2 ∪ F3 | = | F1 | + | F2 | + | F3 | − | F1 ∩ F2 | − | F1 ∩ F3 |
− | F2 ∩ F3 | + | F1 ∩ F2 ∩ F3 |
= 3 × 24 − 3 + 0

So, the onto functions are 34 − 3(24 ) + 3.


Math 2151: Discrete Math for Engineering Relations and Functions
Counting onto functions
Similarly the number of functions f : {1, 2, . . . , m} → {1, 2, . . . , n}
where m > n is calculating by considering
F = { f : {1, 2, . . . , m} → {1, 2, . . . , n} : f is NOT onto} and
expresing
n
[
F= Fi
i =1
where Fi = { f : {1, 2, . . . , m} → {1, 2, . . . , n} : i ∈
/ ran f } (the
functions that miss i) By the inclusion exclusion principle
n
[ n
Fi = ∑ | Fi | − ∑ | Fi ∩ Fj | + ∑ | Fi ∩ Fj ∩ Fk | − · · ·
i =1 i =1 1 ⩽i < j ⩽ n 1 ⩽i < j < k ⩽ n

+ (−1n−1 ) | F1 ∩ · · · ∩ Fn |
   
n m n
= (n − 1) − (n − 2)m + · · · +
n−1 n−2
 
n−1 n
(−1) (n − n)m
0
Math 2151: Discrete Math for Engineering Relations and Functions
Keep on!

From the previous page the NOT onto functions are


n  
k−1 n
∑ (−1) (n − k )m
k=1
n − k

And so, the onto functions are


n   n  
m k−1 n m k n
n − ∑ (−1) (n − k) = ∑ (−1) (n − k )m
k=1
n − k k=0
n − k
n  
k n
= ∑ (−1) (n − k )m
k=0
k

with the last of the summands being zero.

Math 2151: Discrete Math for Engineering Relations and Functions


More counting

We can interpret this as a counting problem.


How many ways are there to distribute 6 different objects into 3
distinguishable boxes so that no box is left empty.
Every one of this ways can be given by a SURJECTIVE function
f : { a, b, c, d, e, f } → {1, 2, 3} where the letters represent the
different objects and the numbers represent the 3 different boxes.
These are
2  
k 3
∑ (−1) k (3 − k)6 = 36 − 3(26 ) + 3 = 540
k=0

Math 2151: Discrete Math for Engineering Relations and Functions


Stirling numbers of the second kind

Definition
The number of ways m DISTINCT objects can be distributed into
n INDISTINGUISHABLE boxes with no box left empty is

1 n
 
k n
S(m, n) = (−1) (n − k )m
n! k∑
=0
k

For m ≥ n there are n!S(m, n) onto functions


f : {1, 2, . . . , m} → {1, 2, . . . , n}

Math 2151: Discrete Math for Engineering Relations and Functions


A counting problem that didn’t fit in the previous page

Count the number of equivalence relations ∼ on the set


A = {1, 2, 3, 4, 5} that have 3 equivalence classes. Answer
S(5, 3).What is the maximum number of equivalence classes that
an equivalence relation ∼⊆ A × A can have?Answer: 5 How many
equivalence relations on A are there?
Answer:

S(5, 1) + S(5, 2) + S(5, 3) + S(5, 4) + S(5, 5)

How many of the previous relations have 1 ∼ 2 ∼ 5? Since 1,2,5


all have to be in the same equivalence class, this problem is
equivalent to counting equivalence relations on the set {3, 4, 5}
which are
S(3, 1) + S(3, 2) + S(3, 3)

Math 2151: Discrete Math for Engineering Relations and Functions


Going back to examples with infinite sets
Let’s try to construct some functions
f : Z → O bijective, where O is the set of odd integers. A
bijection is for example given by f ( x) = 2x + 1. Prove that it
is bijective. Look the book if you don’t know how. Done in
class.
Proof.
Let’s prove that f is injective. If x, y ∈ Z are such that
f ( x) = f ( y), then

2x + 2 = 2y + 1
2x = 2y
x=y

To prove that f : Z → O is surjective, let n ∈ O be an odd


integer. Then, there is x ∈ Z s.t. n = 2x + 1 = f ( x).

Math 2151: Discrete Math for Engineering Relations and Functions


Notice that the function f : Z → Z defined by f ( x) = 2x + 1
(same formula as the previous exercise) is not surjective. For
example 0 is not in ran( f ). This is because if 0 ∈ ran( f ),
then 0 = f ( x) = 2x + 1 for some integer x, that is, 0 is oddd,
which is false.
Now, a function f : Z → Z which is not 1-1. Consider the
function f ( x) = x2 − 2x + 4. Prove that it is not injective.
Suppose that f ( x) = f ( y), then

x2 − 2x + 4 = y2 − 2y + 4
x2 − y2 = 2x − 2y
( x − y)( x + y) = 2( x − y)

The last equation holds when x = y, BUT it also holds when


x ̸= y and x + y = 2.
The function is not injective since f (0) = 4 = f (2), however
0 ̸= 4. (0 and 2 are just two numbers that add up to 2).

Math 2151: Discrete Math for Engineering Relations and Functions


More examples with infinite sets

Prove that the function f : R → R given by f ( x) = x2 − 1 is


not surjective. What is ran( f )?
Here we have that x2 ≥ 0 and so f ( x) = x2 − 1 ≥ −1 for
any real number x. This means that f is not surjective since,
for example, −2 ∈ / ran( f ). Ok, but, what is ran( f )? Let’s try
to prove that ran( f ) = [−1, ∞). Let y ∈ [−1, ∞) we want
to find x s.t. f ( x) = x2 − 1 = y.
From this y + 1 = x2 and so we have that x = ± y + 1. For
p
p p 2
example f ( y + 1) = y + 1 − 1 = y + 1 − 1 = y. We
conclude that ran( f ) = [−1, ∞)

Math 2151: Discrete Math for Engineering Relations and Functions


Similar example
This is something we did in class. Consider the function
f : R \ {0} → R \ {1} defined by the formula
2x + 1
f ( x) =.
2x − 1
You can easily prove that f is injective. Let’s see that f is
surjective. Given y ∈ R \ {1}, that is y ∈ R and y ̸= 1. Let’s find
x s.t. f ( x) = y. If this where true then
2x + 1
=y
2x − 1
2x + 1 = y(2x − 1) = 2xy − y
y + 1 = 2xy − 2x = 2x( y − 1)
y+1
=x
2( y − 1)
y+1
We have a suitable candidate, namely 2y−2 . In the midterm you’ll
have to show that this actually works. Namely (continues next
page).
Math 2151: Discrete Math for Engineering Relations and Functions
Continues from previous page

Ok, we needed to show that y is f (our candidate).


y+1 y+1

y+1
 2 2( y−1) + 1 ( y−1) + 1
f = y+1
= y+1
2( y − 1) 2 2( y−1) − 1 ( y−1) − 1
y+1+ y−1 2y
y−1 y−1
= y+1−( y−1)
= 2
y−1 y−1
2y
=
2
=y

Math 2151: Discrete Math for Engineering Relations and Functions


Some particularly important functions
The following functions are defined in the text.
Absolute value the function: || : R → R defined by
(
x, x≥0
| x| =
− x, x < 0
Floor: ⌊⌋ : R → R defined as follows. If x ∈ R,
⌊ x⌋ = max{n ∈ Z : n ≤ x}
It is also the unique integer that satisfies
x − 1 < ⌊ x⌋ ≤ x
Ceiling:⌈⌉ : R → R defined for x ∈ R as
⌊ x⌋ = min{n ∈ Z : x ≤ n}
It is the unique integer that satisfies
x ≤ ⌈ x⌉ < x + 1
Math 2151: Discrete Math for Engineering Relations and Functions
Inverse function

Definition
A function f : A → B is said to be invertible when the set of pairs

{(b, a) : ( a, b) ∈ f }

is a function f −1 : B → A. Since, for our book, the inverse


function has to have domain B, we have that f is invertible if and
only if f is bijective (1-1 and onto).When f : A → B is bijective
we can define f −1 as follows

f −1 ( b ) = a ⇔ f ( a ) = b

Math 2151: Discrete Math for Engineering Relations and Functions


Finding inverses

Find the inverse to the function f : R → R given by


f ( x) = 2x − 1. f is bijective (try justifying this as an
exercise). An inverse to the function f would be s.t.

f −1 ( y ) = x ⇔ f ( x ) = y
⇔ 2x − 1 = y
⇔ 2x = y + 1
y+1
⇔x=
2
y+1
Altogether this says that f −1 ( y) = 2 .
Remark:
Notice that this is similar to what you have to do to show
that f is surjective. Given y, we find x s.t. f ( x) = y in terms
of y. Since f is injective this x is unique and we call it f −1 ( x)

Math 2151: Discrete Math for Engineering Relations and Functions


The inverse√to f : R → [0, ∞) given by f ( x) = x2 is
f −1 ( x) = x.
The inverse to f : R → (0, ∞ given by f ( x) = e x is
f −1 ( x) = ln( x).

Math 2151: Discrete Math for Engineering Relations and Functions


Examples
Consider the function f : R \ {1/2} → R \ {1/2}
f ( x) = 2x2−1 . Prove that f is injective (exercise). Let’s prove
that f is surjective and find an inverse
g : ran( f ) → R \ {1/2}.
Let’s see that . If y ∈ R we have to show that then f ( x) = y
for some x.
2
f ( x) = y ⇔ =y
2x − 1
⇔ 2 = (2x − 1) y = 2xy − y
⇔ y + 2 = 2xy
y+2
⇔x=
y
 
y+2
So, f y= y when y ̸= 0. This means that
ran( f ) = R \ {0}. This also gives that
y+2
f −1 : R \ {0} → R \ {1/2} is given by f −1 ( y) = y .
Math 2151: Discrete Math for Engineering Relations and Functions
So far so good, but why is it called inverse?

f −1 is the inverse of f with respect to an operation called


composition.
Definition
We define for functions f : A → B and g : B → C the function
g ◦ f of g f : A → C. For a ∈ A this function is defined by

g ◦ f ( a) = g( f ( a))

and it is called the composition of g and f .

Definition
Let A be a set. There is a function 1 A : A → A called the identity
of A s.t. 1 A ( a) = a for all a ∈ A.

Math 2151: Discrete Math for Engineering Relations and Functions


And why is the identity called identity?

The identity 1 A : A → A behaves as an identity with respect to


composition.
Lemma
Let A be a set and consider the function 1 A : A → A if
f : A → B and g : C → A, then

f ◦ 1 A = f , and 1 A ◦ g = g

Lemma
Composition is associative. That is, if f : A → B, g : B → C, and
h : C → D, then
h ◦ ( g ◦ f ) = (h ◦ g) ◦ f

Math 2151: Discrete Math for Engineering Relations and Functions


Examples
A finite example. Let f : {0, 1, 2} → {0, 1, 2, 3} be
f = {(0, 1), (1, 3), (2, 0)} and g : {0, 1, 2, 3} → {0, 1, 2} be
given by g = {(0, 1), (1, 0), (2, 2), (3, 1)} then, their
compositions are

g ◦ f = {(0, 0), (1, 1), (2, 1)} : {0, 1, 2} → {0, 1, 2}


f ◦ g = {(0, 3), (1, 1), (2, 0), (3, 3)}.

An infinite example. Let’s compose two infinite functions.


Consider the function f : R → R given by f ( x) = 2x + 1 and
g( x) : R → R given by g( x) = x2 − 1 then, their
compositions f ◦ g and g ◦ f (both R → R) are given by

f ◦ g( x) = f ( g( x)) = f ( x2 − 1) = 2( x2 − 1) + 1 = 2x2 − 1
g ◦ f ( x) = g( f ( x)) = g(2x + 1) = (2x + 1)2 − 1 = 4x2 + 4x

Math 2151: Discrete Math for Engineering Relations and Functions


Theorem
Let f : A → B, and g : B → A be functions. Then f and g are
inverses of each other if and only if

g ◦ f = 1 A , and f ◦ g = 1 B

Example: Let f : R \ {1/2} → R \ {1} be the function

2x + 1
f ( x) =
2x − 1
Prove that f is a bijective function by finding
g : R \ {1} → R \ {0} s.t. g ◦ f and f ◦ g are identities (and
proving it!).

Math 2151: Discrete Math for Engineering Relations and Functions


Continuous from previous slide

We already have a candidate for the inverse of f that we found


when proving that f is surjective a few slides before. Namely,
y+1
g( y) = 2( y−1) . We found this function by supposing f ( x) = y and
solving for x, getting x = g( y). What we prove was that f ( x) = y
iff x = g( y). If you look closer at what we did, we actually proved
that if y ̸= 1,
 
y+1
f ◦ g( y) = f ( g( y)) = f = y = 1( y),
2( y − 1)

that is, we proved that f ◦ g = 1R\{1} .


To finish we just have to prove that g ◦ f = 1R\{1/2} .

Math 2151: Discrete Math for Engineering Relations and Functions


Continues from previous slide

So, let x ̸= 1/2,


2x+1
2x−1 + 1
 
2x + 1
g ◦ f ( x) = g( f ( x)) = g = 2x+1
2x − 1

2 2x −1 − 1
2x+1+2x−1
2x−1
= 2(2x+1−(2x−1))
2x−1
4x
= = x.
4
So, g ◦ f = 1R\{0} . This proves at once that f has an inverse
f −1 = g and that f is bijective.

Math 2151: Discrete Math for Engineering Relations and Functions


Something fun

Here are some fun bijections.


Hilbert’s Hotel. The set N has the same number of elements
as the set N \ {0} !. Or in Hilbert’s way of looking at it:
there’s always room for one more person in a fully occupied
infinite hotel. You can prove that the function
f : N \ {0} → N given by f (n) = n + 1 is bijective.
Even worse, the set Z has the same number of elements as
the set N. This is because the function f : N → Z given by
(
− n , n even
f (n) = n+21
2 , n odd

is bijective. Here we are using the even numbers to hit the


negative integers and 0, and the odd numbers to hit the
positive integers.

Math 2151: Discrete Math for Engineering Relations and Functions


After the previous example this shouldn’t surprise you.
N × {0, 1} has the same elements as N. Similarly to the
previous exercise we can define f : N → N × {0, 1} by
(
( n2 , 0), n even
f (n) = n−1
( 2 , 1), n odd

Is bijective.
I’ll just explain this one without giving a precise formula. But
there is a bijective function f : N → N × N. To give a
bijection from N to N × N is the same as puting the elements
of N × N in a line without repeating any elements. f (0)
would be the first element in line, f (1) the second element in
line f (2) the third element in line, and so on. Now look at
the picture in the next page

Math 2151: Discrete Math for Engineering Relations and Functions


Cantor’s bijection f : N → N × N

(0, 0) (0, 1) (0, 2) (0, 3) (0, 4) ···

(1, 0) (1, 1) (1, 2) (1, 3) (1, 4) ···

(2, 0) (2, 1) (2, 2) (2, 3) (2, 4) ···

(3, 0) (3, 1) (3, 2) (3, 3) (3, 4) ···

(4, 0) (4, 1) (4, 2) (4, 3) (4, 4) ···

f (0) = (0, 0), f (1) = (1, 0), f (2) = (0, 1), f (3) = (0, 2) and so
on.
Math 2151: Discrete Math for Engineering Relations and Functions
Some uncountable sets

A set A is called countable if there is a bijection f : A → N. By


the previous arguments N × N, N, and Z are all countable sets.
Here is an example of an uncountable set.
Theorem
The interval (0, 1) is not countable.

Proof:
Suppose that there is a function f : N → (0, 1) that was bijective.
We prove that this is impossible by constructing an element
d ∈ (0, 1) which is not any of the f (n)’s. We will write each f (n)
in decimal form as f (n) = 0.an,0 an,1 an,2 an,3 . . .

Math 2151: Discrete Math for Engineering Relations and Functions


(0, 1) is uncountable
Proof.
This would give us the following:

f (0) = 0.a0,0 a0,1 a0,2 a0,3 a0,4 . . .


f (1) = 0.a1,0 a1,1 a1,2 a1,3 a1,4 . . .
f (2) = 0.a2,0 a2,1 a2,2 a2,3 a2,4 . . .
f (3) = 0.a3,0 a3,1 a3,2 a3,3 a3,4 . . .

We will define a number 0.b0 b1 b2 b3 b4 . . . that is not in the list.


(
1, an,n = 0
bn =
0, an,n ̸= 0

The point is that bn ̸= an,n , no matter what an,n is. Thus,


0.b0 b1 b2 . . . cannot equal f (n) = 0.an,0 an,1 an,2 an,3 . . . This is
because if this was the case we would have an,0 = b0 , an,1 = b1 ,
an,2 = b2 and so on... But we made sure that bn ̸= an,n .
Math 2151: Discrete Math for Engineering Relations and Functions
Other uncountable sets

In general all intervals in the real line are of the same size (and
thus, uncountable) if they contain more than one element.
For example if a < b are real numbers, the function
f : (0, 1) → ( a, b) given by f ( x) = (b − a) x + a gives a
bijection between (0, 1) and ( a, b). Can you construct an
inverse to f ?
Even the interval (−∞, ∞) = R has the same number of
elements as, for example, the interval (− π2 , π2 ) as can be seen
from the function tan : (− π2 , π2 ) → R whose inverse is
arctan : R → (− π2 , π2 ).

Math 2151: Discrete Math for Engineering Relations and Functions

You might also like