## 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.

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{.}\)

### Checkpoint 7.1.3. Definition of Functions.

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

select

two elements

each element

no element

half of the elements

exactly one element

some element

The set \(A\) is called the

select

range

image

subset

codomain

domain

superset

preimage

function

select

range

image

subset

codomain

domain

superset

preimage

function

\(n\) | \(\mathrm{studentid}(n)\) |

Aaron | \(1006\) |

Alice | \(1001\) |

Bob | \(1002\) |

Eve | \(1003\) |

James | \(1005\) |

Nathan | \(1007\) |

Oscar | \(1004\) |

Sandi | \(1008\) |

### Example 7.1.5. A function from student names to student IDs.

Let

be the set of students in MAT 112 and

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}\) |

### Example 7.1.7. A function from student IDs to grades.

Let

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.

\(x\) | \(k(x)\) |

\(0\) | \(2\) |

\(1\) | \(4\) |

\(2\) | \(8\) |

\(3\) | \(8\) |

\(4\) | \(4\) |

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).

\(x\) | \(g(x)\) |

\(0\) | \(0\) |

\(1\) | \(1\) |

\(2\) | \(4\) |

\(3\) | \(4\) |

\(4\) | \(1\) |

### Example 7.1.10. A function given by an algebraic rule.

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.

### Example 7.1.11. 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\) |

A function can also be described by an algorithm.

### Example 7.1.12. A function given 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

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.