Skip to main content

Section 7.1 Definition of a Function

A function has three parts, a set of inputs, a set of outputs, and a rule that relates the elements of the set of inputs to the elements of the set of outputs in such a way that each input is assigned exactly one output.

Although for brevity, functions are often identified by a one-letter name, such as \(f\text{,}\) many common functions are identified by multi-letter names. We will see that \(\gcd\) that we saw in the previous chapter is actually an example of a function. Many others you can find on the keys of your calculator, for example: \(\cos\text{,}\) \(\exp\text{,}\) \(\ln\text{,}\) \(\log\text{,}\) \(\sin\text{,}\) \(\tan\text{,}\) and so on.

We give an introduction to functions in the video in Figure 7.1.1. It is followed by a more detailed discussion.

Figure 7.1.1. Definition of a Functions by Matt Farmer and Stephen Steward

We give the definition of a function and its domain and codomain. We also introduce a convenient short notation for specifying the domain and codomain of a function.

Definition 7.1.2.

Let \(A\) and \(B\) be nonempty sets.

  • A function \(f\) from \(A\) to \(B\) assigns exactly one element of \(B\) to each element of \(A\text{.}\) We denote a function \(f\) from \(A\) to \(B\) by \(f \colon A \to B\) and we write \(f(a) = b\) if \(b\) is the unique element of \(B\) that is assigned to the element \(a \in A\) by \(f\text{.}\)

  • We read \(f:A\to B\) as “the function \(f\) from \(A\) to \(B\text{.}\)” We read \(f(a) = b\) as “\(f\) of \(a\) is \(b\)” or “\(f\) evaluated at \(a\) is \(b\text{.}\)

  • The set \(A\) is called the domain of \(f\text{,}\) and the set \(B\) is called the codomain of \(f\text{.}\)

  • Suppose that \(f(a)=b\text{.}\) Then the element \(b\) is the image of the element \(a\) under the function \(f\text{,}\) and the element \(a\) is a preimage of the element \(b\) under the function \(f\text{.}\)

Complete the following:

Let \(A\) and \(B\) be nonempty sets. A function from \(A\) to \(B\) assigns

  • select

  • two elements

  • each element

  • no element

  • half of the elements

  • exactly one element

  • some element

of \(B\) to
  • select

  • two elements

  • each element

  • no element

  • half of the elements

  • exactly one element

  • some element

of \(A\text{.}\)

The set \(A\) is called the

  • select

  • range

  • image

  • subset

  • codomain

  • domain

  • superset

  • preimage

  • function

of the function and the set \(B\) is called the
  • select

  • range

  • image

  • subset

  • codomain

  • domain

  • superset

  • preimage

  • function

of the function.

Answer 1.

\(\text{exactly one element}\)

Answer 2.

\(\text{each element}\)

Answer 3.

\(\text{domain}\)

Answer 4.

\(\text{codomain}\)

\(n\) \(\mathrm{studentid}(n)\)
Aaron \(1006\)
Alice \(1001\)
Bob \(1002\)
Eve \(1003\)
James \(1005\)
Nathan \(1007\)
Oscar \(1004\)
Sandi \(1008\)
Figure 7.1.4. The function \(\mathrm{studentid}:N\to I\) defined by a table. The domain is the set \(N=\{\mathsf{Aaron},\mathsf{Alice},\mathsf{Bob},\mathsf{Eve},\mathsf{James},\mathsf{Nathan},\mathsf{Oscar},\mathsf{Sandi}\}\text{.}\) of names of the students in MAT 112. The codomain is the set \(I=\{1001,1002,1003,1004,1005,1006,1007,1008\}\) of student identification numbers defined by a table.

Let

\begin{equation*} N=\{\mathsf{Aaron},\mathsf{Alice},\mathsf{Bob},\mathsf{Eve},\mathsf{James},\mathsf{Nathan},\mathsf{Oscar},\mathsf{Sandi}\} \end{equation*}

be the set of students in MAT 112 and

\begin{equation*} I=\{1001,1002,1003,1004,1005,1006,1007,1008\} \end{equation*}

the set of student identification numbers.

In Figure 7.1.4 we define a function \(\mathrm{studentid}:N\to I\) that assigns an identification number in the set \(I\) to each student in the set \(S\text{.}\) The set \(N\) of student names is the domain of the function \(\mathrm{studentid}\) and the set \(I\) of student identification numbers is the codomain of \(\mathrm{studentid}\text{.}\)

We have \(\mathrm{studentid}(Alice)=1001\text{.}\) So \(1001\) is the image of Alice under the function \(\mathrm{studentid}\text{.}\) Alice is the preimage of \(1001\) under the function \(\mathrm{studentid}\text{.}\)

\(i\) \(\mathrm{grade}(i)\)
\(1001\) \(\mathsf{B}\)
\(1002\) \(\mathsf{C}\)
\(1003\) \(\mathsf{D}\)
\(1004\) \(\mathsf{F}\)
\(1005\) \(\mathsf{A}\)
\(1006\) \(\mathsf{A}\)
\(1007\) \(\mathsf{A}\)
\(1008\) \(\mathsf{A}\)
Figure 7.1.6. The function \(\mathrm{grade}:I\to G\) where
\begin{equation*} I=\{1001,1002,1003,1004,1005,1006,1007,1008\} \end{equation*}
is the set of student identification numbers and
\begin{equation*} G = \{\mathsf{A}, \mathsf{B}, \mathsf{C}, \mathsf{D}, \mathsf{F} \} \end{equation*}
is the set of possible grades.

Let

\begin{equation*} I=\{1001,1002,1003,1004,1005,1006,1007,1008\} \end{equation*}

be the identification numbers of the students in MAT 112. The teacher of MAT 112 posts the table from Figure 7.1.6 on her door, so that the students can look up their grades their without posting the students names.

The set \(I\) of student identification numbers is the domain of the function \(\mathrm{grade}\) and the set \(G=\{\mathsf{A},\mathsf{B},\,mathsf{C},\mathsf{D},\mathsf{F}\}\) is the codomain of \(\mathrm{grade}\text{.}\)

We have \(\mathrm{grade}(1001)=\mathsf{B}\text{.}\) Which means that the grade of the student with the identification number \(1001\) is \(\mathsf{B}\text{.}\) So the image of \(1001\) under the function \(\mathrm{grade}\) is \(\mathsf{B}\) and \(1001\) is a preimage of \(\mathsf{B}\) under the function \(\mathrm{grade}\text{.}\)

The images of the elements under a function can be specified in different ways. If we can write down all of the elements of the domain of a function, the function can be specified by explicitly giving the images of the elements of the domain. This can, for example, be done with a diagram or a table.

For example the function \(k\) in Figure 7.1.8 is given by a diagram and by a table.

(a) \(k\) given by a diagram
\(x\) \(k(x)\)
\(0\) \(2\)
\(1\) \(4\)
\(2\) \(8\)
\(3\) \(8\)
\(4\) \(4\)
(b) \(k\) given by a table
Figure 7.1.8. Two ways of specifying a function \(k\) from the set \(\Z_5~=~\{0,1,2,3,4\}\) to the set \(\{2,4,8\}\) by a diagram and by a table

Functions can also be specified by an algebraic rule. For a function \(g\text{,}\) we may specify that \(g(x)\) is equal to an algebraic expression in the variable \(x\text{.}\) For example, in Figure 7.1.9, the function \(g\) is given by a diagram in (a), by a table in (b), and by an algebraic rule in (c).

(a) \(g\) given by a diagram
\(x\) \(g(x)\)
\(0\) \(0\)
\(1\) \(1\)
\(2\) \(4\)
\(3\) \(4\)
\(4\) \(1\)
(b) \(g\) given by a table

\(g:\Z_5\to\Z_5\text{,}\) \(g(x):=x^2\fmod 5\)

(c) \(g\) given by an algebraic rule
Figure 7.1.9. Three ways of specifying a function \(g\) from the set \(\Z_5\) to the set \(\Z_5\)where \(\Z_5=\{0,1,2,3,4\}\text{.}\)

The function \(s:\N\to\N\) given by \(s(n):=n^2\) is the function that assigns to each natural number \(n\) its square \(n^2\text{.}\) (Note that we are using \(:=\) because we are defining the output of the function \(s\text{.}\))

We have \(s(1)=1^2=1\text{,}\) \(s(2)=2^2=4\text{,}\) \(s(3)=3^2=9\) and so on. Thus the image of 1 is 1, the image of 2 is 4, and the image of 3 is 9. A preimage of 1 is 1, a preimage of 4 is 2, and a preimage of 9 is 3. The number 2 does not have a preimage, since it is not a square of a natural number.

We give an example of a function, under which each element in the codomain has (infinitely) many preimages.

Let \(\N\) be the set of natural numbers and \(\Z_5=\{0,1,2,3,4\}\text{.}\) Consider the function \(m:\N\to\Z_5\) given by \(m(a):=a\fmod 5\text{.}\) We have \(m(1)=1\text{,}\) \(m(2)=2\text{,}\) \(m(3)=3\text{,}\) \(m(4)=4\text{,}\) \(m(5)=0\text{,}\) \(m(6)=1\text{,}\) and so on.

In the table below, we explicitly give the images under \(m\) for a few elements in the domain.

\(a\) \(m(a)=a\fmod 5\)
\(0\) \(0\)
\(1\) \(1\)
\(2\) \(2\)
\(3\) \(3\)
\(4\) \(4\)
\(5\) \(0\)
\(6\) \(1\)
\(7\) \(2\)
\(8\) \(3\)
\(9\) \(4\)
\(10\) \(0\)
\(11\) \(1\)
\(12\) \(2\)
\(13\) \(3\)
\(14\) \(4\)
\(15\) \(0\)
\(16\) \(1\)
\(17\) \(2\)
\(\vdots\) \(\vdots\)
Notice that the image of \(1\) is \(1\text{.}\) But the number \(1\) has many preimages. For example, the elements \(1\text{,}\) \(6\text{,}\) \(11\text{,}\) and \(16\) in \(\N\) are all preimages of the element \(1\) in \(\Z_5\text{.}\) There are infinitely many preimages of \(1\text{,}\) namely all numbers in the set \(\{a\mid a\in\N \text{ and } a\fmod 5=1\}\text{.}\)

A function can also be described by an algorithm.

The greatest common divisor function takes each pair of natural numbers and assigns to it the natural number that is the greatest common divisor of the two numbers in the pair. So, the greatest common divisor function has domain \(\N\times\N\) and codomain \(\N\text{,}\) and we may write

\begin{equation*} \gcd:\N\times\N\to\N\text{.} \end{equation*}

The function \(\gcd\) is explicitly specified by the Euclidean Algorithm that has a pair of natural numbers as the input and provides a single natural number as the output.