Sub topic 5
Testing graphs with the vertical line test
This chapter assumes you can plot points on the coordinate plane and that you know the definition of a function from the earlier chapters: a rule that assigns exactly one output to each allowed input. You should also be able to read a graph as a set of (x, y) points. Here you turn the definition into a visual check you can run on any graph.
The idea behind the test
A graph in the coordinate plane shows pairs (x, y). The x-coordinate is the input and the y-coordinate is the output. The function rule says each input has only one output. So a graph represents a function only if no x-value appears with two different y-values.
Points with the same x-value lie on the same vertical line. That gives the test:
- Vertical line test. A graph is the graph of a function if and only if no vertical line crosses it at more than one point.
Imagine sliding a vertical ruler from left to right across the graph. At every position, count the points where the ruler touches the graph. If the count is never more than one, the graph is a function. If the count reaches two or more at any position, it is not.
The test checks outputs for one input at a time. A vertical line crossing at two points means one input has two outputs, which breaks the definition.
In practice you do not test every x-value one by one. You look at the shape of the curve and ask where it could fold back over itself.
Worked examples
A parabola that opens upward
The graph of y = x² is a U shape. Any vertical line x = a meets it at exactly one point, (a, a²). The graph passes the test, so y = x² is a function.
Two different inputs can share an output here, for example x = 2 and x = −2 both give 4. That is allowed. The test only forbids one input with two outputs. A horizontal line meeting the graph twice is not a problem for being a function.
A circle
The circle x² + y² = 25 has radius 5 and is centered at the origin. The vertical line x = 3 crosses it at (3, 4) and (3, −4). One input has two outputs, so the circle is not a function.
Solving for y shows why: y = ±√(25 − x²). The ± sign gives two outputs for almost every x.
The top half, y = √(25 − x²), passes the test, and so does the bottom half, y = −√(25 − x²). Each half is a function by itself.
A sideways parabola
The graph of x = y² opens to the right. The line x = 4 meets it at (4, 2) and (4, −2). It fails the test.
Compare this with y = x². Swapping x and y turns a function into a non-function, because the roles of input and output change. The rule "x is the input" is built into the test.
A vertical line
The graph of x = 3 is itself a vertical line. The line x = 3 meets it at infinitely many points. It fails the test, so x = 3 is not a function. The single input 3 would need every real number as an output.
A horizontal line
The graph of y = 3 is a horizontal line. Each vertical line crosses it once. It passes the test. This is a constant function: every input gives the output 3.
Summary of common shapes
| Graph | Equation | Passes the test? | Reason |
|---|---|---|---|
| Line with any non-vertical slope | y = 2x + 1 | Yes | One y per x |
| Horizontal line | y = 3 | Yes | One y per x (constant function) |
| Vertical line | x = 3 | No | One x has every y |
| Upward parabola | y = x² | Yes | One y per x |
| Sideways parabola | x = y² | No | x = 4 gives y = 2 and y = −2 |
| Full circle | x² + y² = 25 | No | x = 3 gives y = 4 and y = −4 |
| Upper half circle | y = √(25 − x²) | Yes | The ± is removed |
Edge cases that cause errors
Open and closed circles
Graphs of piecewise functions may have jumps, where the graph has a gap and continues at another height. Closed (filled) circles mark points that are on the graph. Open circles mark points that are not.
Suppose a graph has a closed circle at (2, 1) and an open circle at (2, 4). The line x = 2 touches only one point of the graph, the closed one. The open circle is not part of the graph. This graph can still be a function.
If both circles at x = 2 are closed, the line meets the graph at two points, and the graph fails.
Holes
A hole is an open circle in a curve. The vertical line at that x-value does not touch the hole. The input is excluded from the domain if nothing else sits at that x. If a separate closed point is placed at that x, the graph has exactly one output there. Count only the points that are filled.
Endpoints where a graph turns back
Consider the sideways parabola again, but only its right-hand tip. At the vertex (0, 0) the vertical line x = 0 touches one point only. A graph can fail only at x-values where two branches exist, not at the tip itself. When you check a shape that folds back, the failure comes from the other x-values.
Only part of the graph is visible
The vertical line test applies to the points the graph actually shows. If the graph is drawn only for x between −2 and 2, you test only those x-values. Arrows at the ends mean the graph continues in that direction, and you assume it does so without turning back, unless the equation says otherwise.
Do not decide from a small window if the rule is known. A sketch of x² + y² = 25 on a very small window near (5, 0) could look like a function. The equation tells you it is not.
Tangent lines
A vertical line that touches the graph at the very edge of a curve is still touching at one point. A vertical tangent, such as at the leftmost point (−5, 0) of the circle, meets the graph once. The test fails only when the line meets it two or more times at the same x-value.
Discrete graphs
If a graph is a set of isolated points, check whether any two points have the same x-coordinate. The points (1, 2), (2, 4), and (3, 4) pass: two points share the y-value 4, but the x-values are all different. The points (1, 2), (1, 3), (2, 4) fail, because x = 1 appears twice with different y-values.
If the same point is listed twice, such as (1, 2) and (1, 2), the line meets one point, not two. The graph still passes.
The test in code
The same idea works for a list of sampled points. Group the outputs by input and report any input with more than one distinct output.
from collections import defaultdict
def repeated_inputs(points):
outputs = defaultdict(set)
for x, y in points:
outputs[x].add(y)
return sorted(x for x, ys in outputs.items() if len(ys) > 1)
circle = [(x, y)
for x in range(-5, 6)
for y in range(-5, 6)
if x**2 + y**2 == 25]
parabola = [(x, x**2) for x in range(-3, 4)]
print(repeated_inputs(circle)) # [-4, -3, 0, 3, 4]
print(repeated_inputs(parabola)) # []The circle has the integer points (±3, ±4), (±4, ±3), (0, ±5), and (±5, 0). The inputs −4, −3, 0, 3, and 4 each have two outputs, so the circle fails. At x = ±5 there is only the output 0, so those inputs are not listed. The parabola has no input with two outputs, so the list is empty.
A sampled check can prove a graph is not a function, because one repeated input is enough. It cannot prove the graph is a function, because points you did not sample may fail.
What the test does not tell you
The vertical line test checks one property: one output per input. It says nothing about these things:
- Domain. The test does not tell you which x-values are allowed. You read the domain from the horizontal extent of the graph.
- Range. The test does not tell you which y-values occur.
- One-to-one behavior. Whether different inputs give different outputs is a separate question. It is tested with horizontal lines, and it is a different property from being a function.
Checklist for using the test
- Identify which axis holds the input. In standard graphs it is the horizontal axis.
- Scan left to right for places where the graph curves back, forms a closed loop, or has a vertical segment.
- At each suspicious x-value, count the filled points on the vertical line.
- Ignore open circles and holes, and count closed circles and solid curve points.
- If you find one x-value with two or more points, the graph is not a function. Otherwise it is.
Exercise
A graph has a closed circle at (1, 5), an open circle at (1, 2), and a solid curve that continues from (1, 2) to the right. Does this graph pass the vertical line test at x = 1?
Show answer
Yes at x = 1. The open circle at (1, 2) is not part of the graph, so the line x = 1 meets only the closed point (1, 5). The graph has one output at x = 1.
Exercise
The graph of x = y² − 1 is a parabola opening to the right with vertex at (−1, 0). Does it pass the vertical line test? Give a vertical line that shows your answer.
Show answer
It fails. The line x = 0 meets the graph where y² − 1 = 0, so at (0, 1) and (0, −1). One input has two outputs, so it is not a function.
Exercise
The set of points {(−2, 4), (−1, 1), (0, 0), (1, 1), (2, 4)} is sampled from y = x². Using the idea of the test, say whether the set is a function, and name the inputs that two points share, if any.
Show answer
It is a function. All five x-values (−2, −1, 0, 1, 2) are different, so no vertical line meets two points. The outputs 1 and 4 each appear twice, but that does not matter for the vertical line test.