### Function examples

A function is a mapping from a set of inputs (the domain) to a set of possible outputs (the codomain). The definition of a function is based on a set of ordered pairs, where the first element in each pair is from the domain and the second is from the codomain. But, a metaphor that makes the idea of a function easier to understand is the function machine, where an input $x$ from the domain $X$ is fed into the machine and the machine spits out the element $y=f(x)$ from the codomain $Y$. Below, the domain is visualized as a set of spheres and the codomain as a set of cubes, so that the function machine transforms spheres into cubes.

We often think of a function as taking a number as its input and producing another number as its output. But, we could make a function machine that operates on different types of objects, so a function is in no way limited to numbers. To illustrate this fact, we start with examples that operate on objects other than numbers. Then, we turn to more traditional functions where the domain and codomain are sets of numbers.

#### Example 1: The mother machine

Let the set $X$ of possible inputs to a function (the domain) be the set of all people. For the purpose of making this example simple, we will assume all people have exactly one mother (i.e., we'll ignore the problem of the origin of our species and not worry about folks such as Adam and Eve). We are going to create a function $m$ from people to people, so let the set of possible outputs of our function (the codomain) also be the set $X$ of people. (We can write this using function notation as $m: X \to X$.) We define the function $m$ so that $m(x)$ is the mother of the person $x$ for all people $x \in X$ (confused?).

If, for example, we put Martin Luther King, Jr. into our mother function, we would get $$m(\text{Martin Luther King, Jr.})=\text{Alberta Williams King}.$$ Or if we put in Madame Curie, we'd get $$m(\text{Marie Skłodowska-Curie})=\text{Bronisława Skłodowski}.$$

This function is a well-defined function, since we assume every element $x \in X$ is mapped via the function machine to a unique element $y \in X$, i.e., every person $x$ has exactly one mother $y$. Although the codomain is the set of all people $X$, it's clear that it will be impossible for this function to output certain people. There's no way the mother function $m$ could output any males, nor could it output any childless females. In other words, the range of the function $m$ is the set of female people who have had children, which is a proper subset of the set $X$ of all people.

#### Example 2: Number of children

A function can output objects of a completely different type than the inputs, as suggested by the above picture where spheres enter the function machine and cubes come out. We could define a function where the domain $X$ is again the set of people but the codomain is a set of numbers.

For example, let the codomain $Y$ be the set of whole numbers and define the function $c$ so that for any person $x$, the function output $c(x)$ is the number of children of the person $x$. Since there is an upper limit on the number of children a person could possibly have, it's clear the range of $c$ is not the entire set $Y$ of whole numbers.

Putting in the same people into the child number function, we'd obtain $c(\text{Martin Luther King, Jr.})=4$ and $c(\text{Marie Skłodowska-Curie})=2.$

#### Example 3: Symbols

The domain and codomain of a function could be sets of any type of objects. For example, the domain could be the set $A = \{\bigcirc, \bigtriangleup, \bigstar,\square \}$ and the codomain could be the set $B=\{\Diamond, \bigstar, \square, \bigcirc, \circ \}$. We could define a function $f$ of the form $$f: \{\bigcirc, \bigtriangleup, \bigstar,\square \} \to \{\Diamond, \bigstar, \square, \bigcirc, \circ\}$$ that maps each of the four symbols in $A$ to one of the five symbols in $B$. We could define the function by $f(\bigcirc)=\Diamond$, $f(\bigtriangleup)= \square$, $f(\bigstar)= \square$, and $f(\square)=\bigstar$. (Equivalently, using the ordered pair definition we could define $f$ by the set of ordered pairs $\{(\bigcirc, \Diamond), (\bigtriangleup, \square ), (\bigstar, \square), (\square,\bigstar) \}$.) Since $f$ never maps onto the elements $\bigcirc$ or $\circ$ of the codomain, the range of the function is the set $\{\Diamond, \bigstar, \square \}$.

#### Example 4: Algebraic formula

We can also define a function using an algebraic formula, such as $f(x)=x^2+1$. Such algebraic formulas are the way many people think of functions, though, as the above examples show, such a formula is not required.

To fully define a function, we need to specify the domain and range. If the domain and range are not specified, it is frequently safe to assume that the domain and range are the set of real numbers. So, if we simply refer to the $f(x)=x^2+1$, we probably mean the function $f: \R \to \R$ where $f(x)=x^2+1$. Since $f(x) \ge 1$, the codomain is the subset of real numbers that are 1 or larger.

We could define a different function $g: \mathbf{Z} \to \mathbf{Z}$ by $g(x)=x^2+1$, where $\mathbf{Z}$ is the set of integers. Since the function $g$ takes only integers as inputs and outputs only integers, it has a different domain and range than $f$. Thus, $g$ is a different function than $f$. However, in most cases, we won't need to worry about such differences.

Even for a functions specified by algebraic formulas such as $f(x)=x^2+1$, we can still think of the function in terms of its definition of a set of ordered pairs. The function $f$ has an infinite number of such ordered pairs $(x,f(x))$. The function $g$ also has an infinite number of ordered pairs $(x,g(x))$, but this set of ordered pairs is much smaller. Most ordered pairs in $f$, such as $(1/2,5/4)$, $(\sqrt{2},3)$, or $(\pi, \pi^2+1)$, are not in the set of ordered pairs for $g$.

For functions whose input is a number and output is a number, we can visualize the set of ordered pairs in terms of its graph.

There's nothing sacred about using the variable $x$ in the algebraic formula defining the function. We could have also defined the function by $f(t)=t^2+1$ or $f(\bigstar) = \bigstar^2+1$, and, assuming the domain and codomain are the real numbers, all formulas indicate the same function that can take a real number as an input, square that number, add 1, and give the result as the output.

#### Example 5: Piecewise formula

An algebraic formula for a function can be much more complicated than the simple example $f(x)=x^2+1$. Any formula that unambiguously assigns an element in the codomain for each element in the domain will define a function. For example, we can use the formula
\begin{align*}
p(x) =
\begin{cases}
-4 & \text{if } x \lt -1\\
3x & \text{if } -1 \le x \lt 4\\
x^2-x & \text{if } x \ge 4
\end{cases}
\end{align*}
to define a function from the real numbers to the real numbers. For any input real number $x$, it first checks if $x \lt -1$ or if $-1 \le x \lt 4$ or if $x \ge 4$, and then it assigns an output using the respective formula. Since for any real number $x$, exactly one of those three conditions is satisfied, the formula unambiguously assigns a real output value $p(x)$ for each $x$. We refer to such a formula as a *piecewise* formula, as it breaks the domain into pieces and uses a separate formula for each piece.

For this definition of $p$, we calculate that, for example, $p(-2) = -4$, $p(-1) = 3(-1)=-3$, and $p(10)=10^2-10=90$.

#### Other examples

As suggested by the function machine metaphor, there's an endless variety to the types of functions you could define. You just need to come up with a collection of objects for the input, a collection of objects for the possible outputs, and decide what the function machine with spit out for each input object.

The input or output objects could even be sets containing many subparts. For example, one could make a function machine that requires both an integer $i$ and a person $p$ as inputs, adds the number $i$ to the number of children of person $p$, and spits out the result as its output. Or one could make a function machine that takes a person $p$ as its input and outputs two numbers: the number of male children and the number of female children of person $p$.

#### Thread navigation

##### Math 201, Spring 2017

- Previous: Function notation
- Next: Function machine parameters

##### Math 1241, Fall 2017

- Previous: Function notation
- Next: Function machine parameters