Sub topic 4
Evaluating a function at a value
What you should already know
This chapter assumes you can do arithmetic with integers, fractions, and decimals, and that you can simplify basic algebraic expressions with exponents and square roots. It also assumes you have read the previous chapter on function notation, so that f(x) and the idea of an input and an output are familiar. Here we focus on the mechanics of evaluating, the errors learners make most often, and how evaluation connects to the domain.
What "evaluate" means
To evaluate a function at a value means to replace the input variable with that value everywhere it appears, then simplify. The result is the output for that input.
For f(x) = 2x + 3, the expression f(4) asks: what output does the rule give when the input is 4? Substitute 4 for every x:
f(4) = 2(4) + 3 = 8 + 3 = 11
The notation f(4) = 11 is a complete statement. It says that the input 4 produces the output 11, and it corresponds to the point (4, 11) on the graph of f.
The Python function below mirrors this notation. Each call evaluates the function at one input.
def f(x):
return 2 * x + 3
print(f(4)) # 11
print(f(-1)) # 1
print(f(1) + f(2)) # 12, because 5 + 7The last line shows that f(1) + f(2) means "evaluate each, then add." It is not the same as f(1 + 2), which we examine below.
A reliable procedure
Use the same steps every time. They prevent most sign and order-of-operations mistakes.
- Copy the rule with the input variable replaced by an empty pair of parentheses.
- Put the input value inside those parentheses.
- Simplify using the order of operations: parentheses, exponents, multiplication and division, then addition and subtraction.
- Write the result as
f(a) = value.
For f(x) = x² − 3x + 1, evaluate at x = −2:
- f( ) = ( )² − 3( ) + 1
- f(−2) = (−2)² − 3(−2) + 1
- = 4 + 6 + 1
- f(−2) = 11
The parentheses around −2 matter. Without them, −2² is read as −(2²) = −4, and the result changes.
Evaluating at algebraic inputs
The input does not have to be a number. You can evaluate a function at a variable or an expression. The rule is the same: replace each x with the whole input, in parentheses, then simplify.
Let f(x) = x² + 2x. Then:
f(a) = a² + 2a. The letter changed, but the rule did not.f(t + 1) = (t + 1)² + 2(t + 1) = t² + 2t + 1 + 2t + 2 = t² + 4t + 3.f(2x) = (2x)² + 2(2x) = 4x² + 4x.f(−x) = (−x)² + 2(−x) = x² − 2x.
Notice what f(2x) shows. Squaring applies to the whole input, so (2x)² is 4x², not 2x².
Evaluation does not distribute
A common error is to treat f as a number that multiplies the parentheses. Function notation is not multiplication. In general:
f(a + b)is notf(a) + f(b).f(2x)is not2f(x).
Check with f(x) = x². Then f(1 + 2) = f(3) = 9, but f(1) + f(2) = 1 + 4 = 5. The two results differ, so the rule does not distribute. The exception is a function of the form f(x) = mx, where distribution does happen to work, but that is a property of that particular rule and not of function notation.
| Expression | Meaning | For f(x) = x² |
|---|---|---|
| `f(1) + f(2)` | Evaluate each, then add | 1 + 4 = 5 |
| `f(1 + 2)` | Add first, then evaluate | f(3) = 9 |
| `f(2x)` | Evaluate at the input 2x | 4x² |
| `2f(x)` | Evaluate at x, then double | 2x² |
Evaluating from other representations
You met several ways to show a function earlier in this tutorial. Evaluation works in each one, but the method differs.
From a table
Find the row with the given input and read the output.
| x | f(x) |
|---|---|
| 0 | 5 |
| 1 | 7 |
| 2 | 9 |
| 3 | 11 |
Here f(2) = 9. If the input is not listed, such as f(2.5), the table does not tell you the output. You cannot assume a pattern unless the problem gives you a rule.
You can also work backward. To solve f(x) = 11, find the row whose output is 11, which gives x = 3. If an output appears in several rows, then several inputs share it.
From a graph
Find the input on the horizontal axis, move vertically to the curve, then read across to the vertical axis. The height of the curve at that input is the output. If the curve passes through (3, 4), then f(3) = 4.
Graph readings are usually approximate. If the curve is between grid lines, give an estimate and say so. Because a function gives one output per input, a vertical line meets the graph at most once, so the reading is unambiguous.
From a mapping
In a mapping diagram, follow the arrow from the input to the output. Each input has exactly one arrow leaving it.
Evaluation and the domain
You can only evaluate a function at an input that is in its domain. If the rule produces an undefined result, the input is outside the domain and f(a) does not exist.
Take g(x) = √(x − 2) / (x − 5). The square root needs x − 2 ≥ 0, so x ≥ 2. The denominator needs x ≠ 5. The function below raises an error for inputs outside the domain.
import math
def g(x):
if x < 2 or x == 5:
raise ValueError("x is outside the domain of g")
return math.sqrt(x - 2) / (x - 5)
print(g(6)) # 2.0
print(g(3)) # -0.5Check the two values by hand:
g(6) = √4 / 1 = 2.g(3) = √1 / (−2) = −0.5.
Now try g(5). The denominator is 0, so the result is undefined. Try g(1). The square root of −1 is not a real number, so the result is undefined as well. In both cases the correct statement is "g(5) is undefined," not "g(5) = 0."
Evaluating with a computed rule
Sometimes a single computation is split into steps. Evaluate each step in order and keep the intermediate results organized.
For h(x) = x², the outputs at the integers from −3 to 3 show two facts.
def h(x):
return x ** 2
outputs = sorted({h(x) for x in range(-3, 4)})
print(outputs) # [0, 1, 4, 9]- Two different inputs can share an output:
h(−2) = h(2) = 4. - No output is negative, because a real number squared is never negative.
A function allows many inputs to give the same output. It does not allow one input to give two outputs. This is the property that makes f(a) a single, well-defined value.
Checking whether pairs define a function
Evaluation depends on each input having one output. When you are given a list of input-output pairs, you can test this directly. The function below returns False as soon as it finds an input with two different outputs.
def is_function(pairs):
seen = {}
for x, y in pairs:
if x in seen and seen[x] != y:
return False
seen[x] = y
return True
relation_a = [(1, 2), (2, 4), (3, 4)]
relation_b = [(1, 2), (1, 3), (2, 4)]
print(is_function(relation_a)) # True
print(is_function(relation_b)) # False
print(sorted({x for x, _ in relation_a})) # domain: [1, 2, 3]
print(sorted({y for _, y in relation_a})) # range: [2, 4]In relation_b, the input 1 gives both 2 and 3, so f(1) has no single value and the relation is not a function. In relation_a, the inputs 2 and 3 share the output 4, which is allowed.
The flow of an evaluation
The diagram shows the decision you make each time you evaluate.
Common errors
- Dropping parentheses on negative inputs. Write
(−3)², not−3². - Substituting into only one
x. Replace every occurrence of the variable. - Treating
f(a + b)asf(a) + f(b). Substitute the whole expression instead. - Reading
f(x)asftimesx. The notation names a function applied to an input. - Calling an undefined value zero. A zero denominator or a negative number under an even root means no output exists.
- Assuming the letter matters.
f(x) = 2x + 3andf(t) = 2t + 3are the same function.
Practice
Exercise
Let f(x) = 3x² − x + 4. Find f(−2) and f(a + 1). Simplify both.
Show answer
f(−2) = 3(−2)² − (−2) + 4 = 12 + 2 + 4 = 18. For f(a + 1), substitute the whole input: 3(a + 1)² − (a + 1) + 4 = 3(a² + 2a + 1) − a − 1 + 4 = 3a² + 6a + 3 − a + 3 = 3a² + 5a + 6.
Exercise
Let g(x) = √(x − 2) / (x − 5). Which of g(2), g(5), and g(1) exist? Give the value when it exists.
Show answer
g(2) = √0 / (−3) = 0, so it exists. g(5) is undefined because the denominator is 0. g(1) is undefined because √(−1) is not a real number.
Exercise
For f(x) = x², show with numbers that f(a + b) is not always f(a) + f(b).
Show answer
Take a = 1 and b = 2. Then f(1 + 2) = f(3) = 9, but f(1) + f(2) = 1 + 4 = 5. Since 9 ≠ 5, the rule does not distribute.