Functions

In mathematics, a function is a special kind of relation between two given sets. More formally, we can define it in the following terms:

Let $X$ and $Y$ be two sets. A function is a relation from $X$ to $Y$ that assigns to each element of $X$ one and only one element of $Y$: $$ f : X \to Y $$

The set $X$ is called the domain of the function, while $Y$ is called the codomain of the function. The domain of a function defines the range of values for which the function is defined. An element $y \in Y$ obtained by evaluating the function at a value $x \in X$ is called the image of $x$ through the function $f$. The set of the all images of a function is called the image (or the range) of the function.

From this last definition, we can notice that the image of a function is a subset of the codomain. It may be either a non-strict or a proper subset of it, depending on whether the function is surjective or not (more on this later).

The usual example is the function $$ f : \mathbb{R} \to \mathbb{R}\\ x \mapsto x^2 $$

whose codomain is $\mathbb{R}$, while its image is the interval $[0, +\infty)$.

Finally, if an element $y \in Y$ is the image of $x \in X$ (i.e., $y = f(x)$), then $x$ is also called the preimage $y$.

Injective functions

Injectivity is a property of mathematical functions. Let’s define it formally:

Let $f : X \to Y$ be a function between two given sets. The function $f$ is said to be injective (or one-to-one function) if distinct elements of its domain have distinct images in the codomain. That is: $$ \forall a, b \in X, \ a \neq b \implies f(a) \neq f(b) $$

For example, we can immediately see that the function $f(x) = x^2$ is not injective since we can easily find two distinct elements $a \neq b$ such that $f(a) = f(b)$. In fact:

$$ f(2) = 2^2 = 4 \ \text{ and } \ f(-2) = (-2)^2 = 4 $$

Therefore, to test whether a function is injective or not, we can prove that, $\forall a,b \in X$, $$ f(a) = f(b) \iff a = b $$

That is, two elements of the domain have the same image only if they are equal.

Let’s look at an example. Let $$ f(x) = \frac{3}{2}x + 1 $$

be a function from $\mathbb{Q}$ to $\mathbb{Q}$. We claim that $f$ is injective. To prove it, we set $f(a) = f(b)$ obtaining:

$$ \begin{aligned} &\frac{3}{2}a + 1 = \frac{3}{2}b + 1\\ &3a + \cancel{2} = 3b + \cancel{2}\\ &3a = 3b\\ & a = b \end{aligned} $$

Therefore the function $f$ is injective on $\mathbb{Q}$.

Surjective functions

Another property of mathematical functions is known as surjectivity. Let’s define it:

Let $f : X \to Y$ be a function between two given sets. The function $f$ is said to be surjective (or onto function) if every element of the codomain is the image of at least one element of the domain. That is: $$ \forall y \in Y, \exists x \in X : y = f(x) $$

In other words, this means that codomain does not have any “unmapped” elements. Furthermore, since as we claimed earlier the image of the function is a subset of the codomain, the function is surjective exactly when its image equals its codomain.

To test whether a function is surjective, we can isolate the $x$ variable and check whether the resulting value belongs to the domain for every $y$ in the codomain.

For instance, let’s consider the function:

$$ y = \frac{3}{2}x + 1 $$

If we multiply both parts of the expression by two and then express it in terms of $x$, we get: $$ \begin{aligned} &2y = 3x + 2\\ &3x = 2y - 2\\ &x = \frac{2(y-1)}{3} \end{aligned} $$

Now we need to prove that, $\forall y \in \mathbb{Q}$, the corresponding value of $x$ is also in $\mathbb{Q}$. Since $y \in \mathbb{Q}$ by assumption, then $(y - 1) \in \mathbb{Q}$ since $\mathbb{Q}$ is closed under subtraction. It’s also true that $2(y-1) \in \mathbb{Q}$ since $\mathbb{Q}$ is also closed under multiplication. Finally, dividing by the nonzero rational number $3$ keeps us inside $\mathbb{Q}$. Therefore $x \in \mathbb{Q}$ and the function $f$ is surjective.

On the other hand, the following function is not surjective: $$ g : \mathbb{N} \to \mathbb{N}\\ x \mapsto 2x $$

To prove this, we observe that every value in the image of $g$ is even. Thus, if we consider the element $1 \in \mathbb{N}$ in the codomain, we note that there is no element $x \in \mathbb{N}$ in the domain such that: $$ g(x) = 1 $$

Indeed:

$$ 2x = 1 \implies x = \frac{1}{2} \notin \mathbb{N} $$

Therefore, $1 \in \mathbb{N}$ is an element of the codomain that is not an image of $g$. Hence, the function $g$ is not surjective.

Bijective function

The last property of mathematical functions that we will discuss in this guide is called bijectivity. It states the following:

Let $f : X \to Y$ be a function between two sets $X$ and $Y$, the function $f$ is bijective if it is both injective and surjective.

When a function is bijective, we can build a new function, called the inverse function and denoted by $f^{-1}$, that maps each element of the codomain to exactly one element of the domain.

An inverse function $f^{-1} : Y \to X$ exists only if and only if $f$ is bijective. Therefore, bijectivity is a necessary and sufficient condition for the existence of an inverse function. Finally, the expression of the inverse function corresponds to the one obtained when proving surjectivity.

Function composition

Given two distinct functions we can create a new one using their composition.

Given two functions $f : X \to Y$ and $g: Y \to Z$, such that the codomain of $f$ is the domain $g$, their composition is a function $g \circ f : X \to Z$ defined as: $$ (g \circ f) (x) = g(f(x)) $$

In other words, the composition of two functions $f$ and $g$ is the function obtained by applying $f$ to $x$ first and then by applying $g$ to the result of $f(x)$.

The composition of two functions does not satisfy, in general, the commutative property, that is: $$ f \circ g \neq g \circ f $$

Instead, it does satisfy associative property, that is: $$ (h \circ g) \circ f = h \circ (g \circ f) $$

For example, let: $$ f(x) = x + 1, \qquad g(x) = 2x, \qquad h(x) = x^2 $$

First, let’s find $(h \circ g)$:

$$ (h \circ g)(x) = h(g(x)) = h(2x) = (2x)^2 = 4x^2 $$

Now let’s move to $(h \circ g) \circ f$:

$$ \begin{aligned} ((h \circ g) \circ f)(x) &= (h \circ g)(f(x))\\ &= \boxed{4(x+1)^2} \end{aligned} $$

Now let’s consider the right-hand side of the property. Let’s start with $(g \circ f)$:

$$ (g \circ f)(x) = g(f(x)) = g(x+1) = 2(x+1) $$

Finally, let’s evaluate $h \circ (g \circ f)$:

$$ \begin{aligned} (h \circ (g \circ f))(x) &= h((g \circ f)(x))\\ &= h(2(x+1)) = (2(x+1))^2\\ &= \boxed{4(x+1)^2} \end{aligned} $$