1.3 Functions

A function is a rule that describes how one number variable depends on other number variables. When we define a function,
  • we declare the output variable and the input variables,
  • we give a defining rule,
  • we optionally name the function, and
  • we optionally declare restrictions.
We'll focus on the first three aspects of functions, and we'll come back to discuss restrictions by the end of this chapter.
Example.
Let's see an example of a function definition.
\[ \begin{align} z &\mathrel{\overset{f}{\leftarrow}} x \\ z &= x^2 + x + 3 \end{align} \]
The first line declares that our function has \( z \) as its output variable and \( x \) as its only input variable. The second line, \( z = x^2 + x + 3 \), is the defining rule. The defining rule tells us how \( z \) depends on \( x \). We gave our function the name \( f \), and we didn't declare any restrictions.
Just as we may evaluate a schematic by placing values on the input wires, we apply a function by substituting input values into the defining rule.
Example.
Let's make a table of values by applying the above function to various inputs.
\[ \begin{align} &f (-2) = (-2)^2 + (- 2) + 3 = 5 \\ &f (-1) = (-1)^2 + (- 1) + 3 = 3 \\ &f \of 0 = 0^2 + 0 + 3 = 3 \\ &f \of 1 = 1^2 + 1 + 3 = 5 \\ &f \of 2 = 2^2 + 2 + 3 = 9 \end{align} \]
\( x \) \( z \)
\( -2 \) \( 5 \)
\( -1 \) \( 3 \)
\( 0 \) \( 3 \)
\( 1 \) \( 5 \)
\( 2 \) \( 9 \)
Notice that some \( z \)-values appear multiple times in the table of values. For example, our function gives the same output \( z = 5 \) to both \( x = -2 \) and \( x = 1 \).
Let's look at a function that has two input variables.
Example.
Consider the function
\[ \begin{align} z &\mathrel{\overset{g}{\leftarrow}} (x, y) \\ z &= 5 x + 4 x y - 2. \end{align} \]
To apply this function, we'll give a value for each of the input variables.
\[ \begin{align} &g (0, 0) = 5 \mult 0 + 4 \mult 0 \mult 0 - 2 = -2 \\ &g (1, 0) = 5 \mult 1 + 4 \mult 1 \mult 0 - 2 = 3 \\ &g (0, 1) = 5 \mult 0 + 4 \mult 0 \mult 1 - 2 = -2 \end{align} \]
We substitute the first input value for \( x \) and the second for \( y \).
We'll end this section with a discussion of notation for functions and operations. Here are three equivalent ways to write a function application.
\[ \begin{align} f \of 7 &= f (7) = (f \of 7) \end{align} \]
We won't require parentheses when we apply a function that has one input variable, but they may be included for clarity. If a function expects two inputs, we will place parentheses around the pair of input values.
\[ \begin{align} &g (3, 1) \end{align} \]
When we perform arithmetic, we'll use the usual order of operations. For example, division binds before addition, and so
\[ \begin{align} &8 + x / 4 \end{align} \]
should be read as \( 8 + (x / 4) \) and not \( (8 + x) / 4 \). Function application binds before any arithmetic operation: addition, subtraction, multiplication, division. As a result,
\[ \begin{align} &f \of 4 + 6 \end{align} \]
means \( (f \of 4) + 6 \) and not \( f (4 + 6) \). We may always group expressions with parentheses to override the order of operations.