07 Functions
07 Functions
Lecture 7
Announcements
• Midterm in 2 weeks
Functions
Functions
Definition:
A function 𝑓 from a set 𝐴 to a set 𝐵 is an assignment of each element of
𝐴 to exactly one element of 𝐵.
• 𝐴 the domain of 𝑓
• 𝐵 the codomain of 𝑓
𝐴 𝐵
𝑓: 1,2,3 → {𝑎, 𝑏, 𝑐}
1 𝑎 𝑓 1 =𝑎
𝑓 2 =𝑏
2 𝑏
𝑓 3 =𝑎
3 𝑐 Domain of 𝑓 is {1,2,3}
Codomain of 𝑓 is {𝑎, 𝑏, 𝑐}
Range of 𝑓 is {𝑎, 𝑏}
Function Non-Example
𝐴 𝐵
The element 1 ∈ 𝐴 is
mapped to two elements
1 𝑎 of 𝐵. Not allowed!
2 𝑏
The element 3 ∈ 𝐴 is not
mapped to any element
3 𝑐 of 𝐵. Not allowed!
Function Examples
• 𝑓 ∶ 1, 2, 3, 4, 5 → {1, 4, 9, 16, 25, 36, 49} where 𝑓 𝑥 = 𝑥 2 .
Square function, except only possible inputs are {1,2,3,4,5}. Observe
that 𝑓’s range is {1, 4, 9, 16, 25}.
• 𝑔 ∶ ℝ → ℤ where 𝑔 𝑥 = 𝑥
This is the floor function, which rounds 𝑥 down to the largest integer less
than or equal to 𝑥. For example, 1.75 = 1, and −2.3 = −3.
1 1
𝑎 𝑎 Is not
Is 2
2 injective! injective!
𝑏 𝑏
3 3
𝑐 𝑐 4
4
Injective Functions
A function 𝑓: 𝐴 → 𝐵 is injective (or one-to-one) if for all 𝑥, 𝑦 ∈ 𝐴, if 𝑥 ≠ 𝑦,
then 𝑓 𝑥 ≠ 𝑓(𝑦).
1
𝑎 𝑎 Is not
Is 2
1 surjective! surjective!
𝑏 𝑏
2 3
𝑐 𝑐 4
𝑓: 𝐴 → 𝐵 is surjective if for
Surjective Example 1 every 𝑏 ∈ 𝐵, there exists some
𝑎 ∈ 𝐴 such that 𝑓 𝑎 = 𝑏.
1
(If there were, then 0 = 2𝑎 + 1, so 𝑎 = − , which is not a natural
2
number).
𝑓: 𝐴 → 𝐵 is surjective if for
Surjective Example 2 every 𝑏 ∈ 𝐵, there exists some
𝑎 ∈ 𝐴 such that 𝑓 𝑎 = 𝑏.
𝑏−1
Let 𝑏 ∈ ℝ be arbitrary. Let 𝑎 = .
Since 𝑏 ∈ ℝ, then 𝑎 ∈ ℝ.
2
Furthermore, observe that:
𝑏−1
𝑓 𝑎 =2 +1= 𝑏−1 +1=𝑏
2
Since every 𝑏 ∈ 𝐵 has an 𝑎 ∈ 𝐴 where 𝑓 𝑎 = 𝑏, 𝑓 is surjective.
Proof Templates
Claim: 𝑓: 𝐴 → 𝐵 is injective. Claim: 𝑓: 𝐴 → 𝐵 is surjective.
Proof:
Proof:
Let 𝑥, 𝑦 ∈ 𝐴 be arbitrary, and assume
𝑓 𝑥 = 𝑓(𝑦). Let 𝑏 ∈ 𝐵 be arbitrary.
… …
Apply algebra, logic, Find an 𝑎 ∈ 𝐴 where
creativity 𝑓 𝑎 = 𝑏 and show it works
… …
Therefore 𝑥 = 𝑦.
Since every 𝑏 ∈ 𝐵 has an 𝑎 ∈ 𝐴 where
Since 𝑓 𝑥 = 𝑓(𝑦) implies 𝑥 = 𝑦, 𝑓 is
injective. 𝑓 𝑎 = 𝑏, 𝑓 is surjective.
Bijective Functions
Definition:
A function 𝑓: 𝐴 → 𝐵 is bijective if: it is both injective and surjective.
𝑎 1 Is
bijective!
𝑏 2
𝑐 3
Note
For a function 𝑓: 𝐴 → 𝐵, the sets 𝐴 and 𝐵 might themselves be
constructed with various set operations.
• E.g. 𝑔: ℝ × ℝ → ℝ where 𝑔 𝑥, 𝑦 = 𝑥 2 + 𝑦.
Takes as input a pair from ℝ × ℝ, i.e. two reals, and returns a real.
𝐴 𝐵 𝐶
𝑔 𝑓
𝑎 𝑔(𝑎) 𝑓 𝑔 𝑎
Composition
Definition: Let 𝑔: 𝐴 → 𝐵, 𝑓: 𝐵 → 𝐶 be functions. Then the composition
𝑓 ∘ 𝑔 ∶ 𝐴 → 𝐶 where 𝑓 ∘ 𝑔 𝑎 = 𝑓 𝑔 𝑎
𝐴 𝐵 𝐶
𝑔 𝑓
𝑎 𝑔(𝑎) 𝑓 𝑔 𝑎
Composition Example 1
Suppose we have:
𝑔 ∶ ℝ → ℝ where 𝑔 𝑥 = 𝑥 + 1
𝑓 ∶ ℝ → ℝ where 𝑓 𝑥 = 𝑥 2
𝑓 ∘ 𝑔 ∶ ℝ → ℝ where 𝑓 ∘ 𝑔 𝑥 = 𝑓 𝑔 𝑥 = 𝑥+1 2
𝑔 ∘ 𝑓: ℝ → ℝ where 𝑔 ∘ 𝑓 𝑥 = 𝑔 𝑓 𝑥 = 𝑥2 + 1
Composition Example 2
Suppose we have:
𝑔 ∶ ℕ → ℝ where 𝑔 𝑥 = 𝑥
𝑓 ∶ ℝ → ℝ where 𝑓 𝑥 = 𝑥 − 3
Optional practice!
Inverting Functions
Inverse
Every bijection from 𝐴 to 𝐵 also has an inverse function.
𝑓 𝑓 −1
𝑎 1 𝑎 1
𝑏 2 𝑏 2
𝑐 3 𝑐 3
Inverse
Why are inverses only defined on bijections?
𝑎
1
𝑏
2
𝑐
1
𝑎
2
𝑏
3
𝑐 4
Then the inverse is not a function, as some elements don’t have any
possible mappings.
Example
Are the following functions invertible?
𝑚 ∶ ℝ → ℝ where 𝑚 𝑥 = 2𝑥 − 5
Yes, because 𝑚 is a bijection (can prove). 𝑚−1 : ℝ → ℝ is defined
𝑥+5
−1
𝑚 𝑥 = .
2