Skip to main content

Introduction to Discrete Mathematics

Chapter 2 Functions

Let \(X\) and \(Y\) be two nonempty sets. A function \(f\) from \(X\) to \(Y\) is a subset of \(X\times Y\) such that for every \(x\in X\text{,}\) there exists a unique \(y\in Y\) such that \((x,y)\in f\text{.}\) The set \(X\) is called the domain of \(f\) and is denoted by \({\dom(f)}\text{.}\) The set \(Y\) is called the codomain of \(f\) and is denoted by \({\codom(f)}\) while the subset of the codomain defined via
\begin{equation*} {\range(f)\:= \{y\in Y\mid \mbox{there exists } x\mbox{ such that } (x,y)\in f\}} \end{equation*}
is called the range of \(f\) or the image of \(X\) under \(f\text{.}\)
There is a variety of notation and terminology associated to functions. We will write \({f:X\to Y}\) to indicate that \(f\) is a function from \(X\) to \(Y\text{.}\) We will make use of statements such as β€œLet \(f:X\to Y\) be the function defined via…” or β€œDefine \(f:X\to Y\) via…”, where \(f\) is understood to be a function in the second statement. Sometimes the word mapping (or map) is used in place of the word function. If \((x,y)\in f\) for a function \(f\text{,}\) we often write \({f(x)=y}\) and say that β€œ\(f\) maps \(x\) to \(y\)” or β€œ\(f\) of \(x\) equals \(y\)”. In this case, \(x\) may be called an input of \(f\) and is the preimage of \(y\) under \(f\) while \(y\) is called an output of \(f\) and is the image of \(x\) under \(f\text{.}\) Note that the domain of a function is the set of inputs while the range is the set of outputs for the function.
Sometimes we can represent functions visual representations called function (or mapping) diagrams, where the elements of the domain and codomain are indicated by labeled nodes and ordered pairs for the function are indicated by an arrow pointing from the node for input to the node for the output. When drawing function diagrams, it is standard practice to put the elements for the domain on the left and the elements for the codomain on the right, so that all directed edges point from left to right. We may also draw an additional arrow labeled by the name of the function from the domain to the codomain.

Example 2.1.

FigureΒ 2.1 depicts a function \(f:X\to Y\) for the sets \(X=\{a,b,c,d\}\) to \(Y=\{1,2,3,4\}\text{.}\) In this case, we see that \(\range(f)=\{1,2,4\}\text{.}\) Moreover, we can write things like \(f(a)=2\) and \(c\mapsto 4\text{,}\) and say things like β€œ\(f\) maps \(b\) to 4” and β€œthe image of \(d\) is 1.” Note that it is perfectly okay to have both \(b\) and \(c\) mapped to 4.
Function diagram from a four-element set to a four-element set.
Function diagram for a function from \(X=\{a,b,c,d,\}\) to \(Y=\{1,2,3,4\}\text{,}\) where \(a\) maps to \(2\text{,}\) \(b\) and \(c\) map to \(4\text{,}\) and \(d\) maps to \(1\text{.}\)
Figure 2.1. Function diagram for a function from \(X=\{a,b,c,d,\}\) to \(Y=\{1,2,3,4\}\text{.}\)
Sometimes we can define a function using a formula. For example, we can write \(f(x)=x^2-1\) to mean that each \(x\) in the domain of \(f\) maps to \(x^2-1\) in the codomain. However, notice that providing only a formula is ambiguous! A function is determined by its domain, codomain, and the correspondence between these two sets. If we only provide a description for the correspondence, it is not clear what the domain and codomain are. Two functions that are defined by the same formula, but have different domains or codomains are not equal. It is important to point out that not every function can be described using a formula! Despite your prior experience, functions that can be represented succinctly using a formula are rare.

Example 2.2.

The function \(f:\mathbb{R}\to \mathbb{R}\) defined via \(f(x)=x^{2}-1\) is not equal to the function \(g:\mathbb{N}\to\mathbb{R}\) defined by \(g(x)=x^{2}-1\) since the two functions do not have the same domain.

Problem 2.3.

Provide an example of each of the following. You may draw a function diagram, write down a list of ordered pairs that represents the assignment, or write a formula as long as the domain and codomain are clear.
  1. A function \(f\) from a set with 4 elements to a set with 3 elements such that \(\range(f)=\codom(f)\text{.}\)
  2. A function \(g\) from a set with 4 elements to a set with 3 elements such that \(\range(g)\) is strictly smaller than \(\codom(g)\text{.}\)

Problem 2.4.

In high school you may have been told that a graph represents a function if it passes the vertical line test. Carefully state what the vertical line test says and then explain why it works.
A piecewise-defined function (or piecewise function) is a function defined by specifying its output on a partition (i.e., β€œdisjoint chunks” ) of the domain. Note that β€œpiecewise” is a way of expressing the function, rather than a property of the function itself.

Example 2.5.

The function \(f:\mathbb{R}\to \mathbb{R}\) defined via
\begin{equation*} f(x)=\begin{cases}x^2-1, \amp \mbox{if } x\geq 0,\\ 17, \amp \mbox{if } -2\leq x\lt 0,\\ -x, \amp \mbox{if } x\lt -2 \end{cases} \end{equation*}
is an example of a piecewise-defined function.

Problem 2.6.

Define \(f:\mathbb{R}\setminus\{0\}\to \mathbb{R}\) via \(f(x)=\frac{|x|}{x}\text{.}\) Express \(f\) as a piecewise function.
Let \(f:X\to Y\) be a function. We define the following.
  1. The function \(f\) is said to be injective (or one-to-one) if for all \(y\in \range(f)\text{,}\) there is a unique \(x\in X\) such that \(y=f(x)\text{.}\) Said another way, \(f\) is one-to-one provided \(f(x) = f(y)\) implies that \(x = y\text{,}\) or equivalently \(x \ne y\) (in \(X\)) implies \(f(x) \ne f(y)\text{.}\) That is, different inputs produce different outputs.
  2. The function \(f\) is said to be surjective (or onto) if for all \(y\in Y\text{,}\) there exists \(x\in X\) such that \(y=f(x)\text{.}\)
  3. If \(f\) is both injective and surjective, we say that \(f\) is bijective.

Problem 2.8.

Assume that \(X\) and \(Y\) are finite sets. Provide an example of each of the following. You may draw a function diagram, write down a list of ordered pairs, or write a formula as long as the domain and codomain are clear.
  1. A function \(f:X\to Y\) that is injective but not surjective.
  2. A function \(f:X\to Y\) that is surjective but not injective.
  3. A function \(f:X\to Y\) that is a bijection.
  4. A function \(f:X\to Y\) that is neither injective nor surjective.

Problem 2.9.

Determine whether each of the following functions is injective, surjective, both, or neither.
  1. Define \(f:\mathbb{R}\to \mathbb{R}\) via \(f(x)=x^{2}\)
  2. Define \(g:\mathbb{R}\to [0,\infty)\) via \(g(x)=x^{2}\)
  3. Define \(h:\mathbb{R}\to \mathbb{R}\) via \(h(x)=x^{3}\)
  4. Define \(k:\mathbb{R}\to \mathbb{R}\) via \(k(x)=x^{3}-x\)
  5. Define \(c: \mathbb{R}\times \mathbb{R}\to \mathbb{R}\) via \(c(x,y)=x^{2}+y^{2}\)
  6. Define \(f:\mathbb{N}\to \mathbb{N}\times \mathbb{N}\) via \(f(n)=(n,n)\)
  7. Define \(g:\mathbb{Z}\to \mathbb{Z}\) via
    \begin{equation*} g(n)=\begin{cases}\frac{n}{2}, \amp \text{ if } n\text{ is even } \\ \frac{n+1}{2}, \amp \text{ if } n\text{ is odd } \end{cases} \end{equation*}
  8. Define \(\ell:\mathbb{Z}\to \mathbb{N}\) via
    \begin{equation*} \ell(n)=\begin{cases}2n+1, \amp \text{ if } n\geq 0\\ -2n, \amp \text{ if } n\lt 0 \end{cases} \end{equation*}

Problem 2.10.

Suppose \(X\subseteq \mathbb{R}\) and \(f:X\to \mathbb{R}\) is a function. Fill in the blank with the appropriate word.
The function \(f:X\to \mathbb{R}\) is Β  Β  Β  Β  Β  Β  Β  Β  if and only if every horizontal line hits the graph of \(f\) at most once.
This statement is often called the horizontal line test. Explain why the horizontal line test is true. What kind of theorems to we get if we replace β€œat most once” with either β€œat least once” or β€œexactly once”?

Problem 2.11.

Suppose \(f:A\to B\) is a function for finite sets \(A\) and \(B\text{.}\) Explain why each of the following statements is true.
  1. If \(f\) is an injection, then \(|A|\leq |B|\text{.}\)
  2. If \(f\) is a surjection, then \(|A|\geq |B|\text{.}\)
  3. If \(f\) is a bijection, then \(|A|=|B|\text{.}\)

Problem 2.12.

Let \(A\) and \(B\) be nonempty finite sets with \(|A|=n\) and \(|B|=k\text{.}\)
  1. How many different functions are there from \(A\) to \(B\text{?}\)
  2. If \(n\leq k\text{,}\) how many injective functions are there from \(A\) to \(B\text{?}\)
  3. If \(n=k\text{,}\) how many bijective functions are there from \(A\) to \(B\text{?}\)
  4. If \(n\geq k\text{,}\) do you think it would be challenging to count the number of surjective functions from \(A\) to \(B\text{?}\)
The next theorem states an important counting technique, which we refer to as the Bijection Principle.

Problem 2.14.

Let \(A\) denote the set of ways to distribute candy in ProblemΒ 1.41 (in the situation where the candy is all identical) and let \(B\) denote the set of sequence of coin flips in ProblemΒ 1.28. Find a bijection \(f:A\to B\text{.}\)
The next problem illustrates that some care must be taken when attempting to define a function.

Problem 2.16.

For each of the following, explain why the given description does not define a function.
  1. Define \(f:\{1,2,3\}\to \{1,2,3\}\) via \(f(a)=a-1\text{.}\)
  2. Define \(g:\mathbb{N}\to \mathbb{Q}\) via \(g(n)=\frac{n}{n-1}\text{.}\)
  3. Let \(A_1=\{1,2,3\}\) and \(A_2=\{3,4,5\}\text{.}\) Define \(h:A_1\cup A_2\to \{1,2\}\) via
    \begin{equation*} h(x)=\begin{cases}1, \amp \mbox{if } x\in A_1\\ 2, \amp \mbox{if } x\in A_2. \end{cases} \end{equation*}
  4. Define \(s:\mathbb{Q}\to \mathbb{Z}\) via \(s(a/b)=a+b\text{.}\)
In mathematics, we say that an expression is well defined (or unambiguous) if its definition yields a unique interpretation. Otherwise, we say that the expression is not well defined (or is ambiguous). For example, if \(a,b,c\in\mathbb{R}\text{,}\) then the expression \(abc\) is well defined since it does not matter if we interpret this as \((ab)c\) or \(a(bc)\) since the real numbers are associative under multiplication.
When we attempt to define a function, it may not be clear without doing some work that our definition really does yield a function. If there is some potential ambiguity in the definition of a function that ends up not causing any issues, we say that the function is well defined. However, this phrase is a bit of misnomer since all functions are well defined. The issue of whether a description for a proposed function is well defined often arises when defining things in terms of how an element of the domain is written. For example, the descriptions given in PartsΒ (c) andΒ (d) of ProblemΒ 2.16 are not well defined.