What is a Function?
Despite the concept of a function being one of the fundamental building blocks of math, I believe that it is often introduced in such a way early schooling that makes it harder to generalize to the understanding that required in higher math. My goal here is to introduce the idea of a function in an understandable manner that makes this transition easier.
When you first were introduced to a function in grade school it was likely of the form: y = mx + b, accompanied with some corresponding graph in ℝ². Perhaps later you were told that this same function can be expressed as f(x) = mx + b where you can take f(x) as some black box machine that takes in values of x and spits out values of the form f(x) = mx + b. To begin with this notation is already ambiguous. When we say f(x) do we mean the function evaluated at x or just the abstract idea of that function itself? Additionally, as we will later see, it become necessary to define the ‘space’ from which the function takes input, and to which the function outputs, all of which is not afforded by our old notation.
What is a function?
At it core a function is a relationship between sets where every element in the first set, called the domain (which we will denote X), is assigned a unique element in a second set called the codomain (which we will denote Y). We denote this relation in one of a few ways, most commonly as:
𝑓: X → Y
𝑥 ↦ 𝑓(x)
The first line specifies the sets that we are working on while the second species the particular rules we are using to associate elements between these two sets. More formally, a function between two sets X and Y is a rule that for every element a in X, associates (or maps) a unique element y= 𝑓(x) in Y. Be careful to notice the two conditions that have snuck in here! We assert that every function must apply to all elements in the domain, and two elements of the codomain cannot be associated to more than one element in the domain.
This relation is not a function for two reason. The first is that there are two elements in the domain that are not associated to elements in the codomain, and the second is that there is an element in the codomain associated to two elements in the codomain.
Let’s practice writing the familiar function 𝑓(x)= x² using this new language. We would say: f: ℝ→ ℝ where x ↦ x². f: ℝ→ ℝ tells us that we are dealing with a function that associates real numbers with other real number, while x ↦ x² specifies that relation.
Before we continue let add to our vocabulary to help us describe some more properties of functions. We have already introduced the idea of the domain and codomain. Now let’s introduce the ideas of the image of an element of the codomain and the range of a function and we will use the following image of valid function 𝑓 to ground our examples.
Definition: We say that the image of an element of the domain under the function 𝑓, is the element associated with x by 𝑓 in the codomain of 𝑓.
Notice that the image of x must be unique by our construction of a function. In this example we see that the image of 1 under 𝑓 is D and the image of 2 under 𝑓 is equal to the image of 3 under 𝑓 which is equal to C. It is perfectly fine for a function to associate two elements to elements of the domain with the codomain, just not the other way around. This property may become familiar in the comparison of the following relationships from ℝ→ ℝ:
The first (in blue) we would would not consider to be a function because on element of the domain, say 9, maps to two elements of the codomain: -3, 3. While the second is clearly a familiar function although multiple elements in the domain are mapped in the same element of the codomain.
The range of a function is a subset of the domain that consists of all of the images of the elements in X. As such the range of our example function 𝑓 is the set {C, D}. Note the domain is sometimes also referred to as the image of the function, not to be confused with the image of an element in the domain as described earlier.
Injective, Surjective and Bijective
Now we are ready to move on to the three most important concepts today: injectivity, surjectivity and bijectivity.
We say that an function 𝑓 is injective if each element of the codomain Y is the image of no more than one element of the domain X. In other words, a function is injective if it is there are no cases where multiple elements of the domain map to the same element in the codomain.
A function is surjective or “onto” if each element in the codomain is the image of at least one element in the domain. Another way to say this is that the range of the function is equal to the codomain.
Finally, a function is bijective if and only if it is both surjective and injective. This implies that each element in the domain is mapped to each element in the codomain exactly once.
The following image summarizes these properties really well, it was taken from Marcus’s Chiu’s var/log which I highly recommend taking a look at.,
We are done! Now you might ask why this is necessary. It seems like a lot of extra work to write f: ℝ→ ℝ where x ↦ x² instead of f(x)= x². But I’d argue that there are at least two good reasons to make this change.
The first is that it encourages what I believe to be a better intuition. Which is instead of thinking of a function as a box that takes in a number and spits out another number, think of it a relationship between sets because this is much more general. For example imagine the function that associates a person with the house they live in. This will not be a bijection since many people often live in the same house, in fact it may not even be a function if you consider people who own more than one house!
The second reason is a corollary of the first. There are often time when we like or need the extra expressiveness of the second method. For example one function is the differentiation function that differentiates some real polynomial:
D: P(ℝ)→ P(ℝ) (where P(ℝ) is the set of all real polynomials)
p ↦ p′
Another example is:
h: ℤ→ ℕ (where ℤ is the set of integers and ℕ is the natural numbers)
h(n)=n²
Here and in other cases is necessary to know the ‘spaces’ that are domain and codomain. In the case the space of all real polynomials. It is also useful to be able to specify the domain and codomain of an arbitrary function without having to specify the particular map.