Relations and Functions

Learning goals

  • Define a relation as a set of ordered pairs
  • Ask which variable is the input before calling it a function
  • Treat the domain as part of the function, not a leftover
  • Separate the natural domain from a declared one
  • Distinguish the range from the codomain it sits inside

A relation is the object underneath

Before a function there is a relation. A relation between two variables xx and yy is simply a set of ordered pairs (x,y)(x, y). The set R={(1,5),(2,5),(3,7)}R = \{(1, 5), (2, 5), (3, 7)\} is already a relation, all by itself: three points, nothing more. Reading xx as the input, RR pairs 11 with 55, 22 with 55, and 33 with 77. A repeated output like the two 55s is allowed; the only thing that would cause trouble is a repeated input, and no input repeats here, so RR is a function of xx. Read yy as the input instead and the pairs read 5→15 \to 1, 5→25 \to 2, and 7→37 \to 3: now the input 55 has two different outputs, 11 and 22, so RR is not a function of yy. Same three points, opposite verdict.

An equation in xx and yy is a second, usually infinite, way to name a relation. The equation carves out of the whole plane exactly those points whose coordinates make the equation true, and that set of points is the relation. The equation y=2x+1y = 2x + 1 names a line, the equation x2+y2=1x^2 + y^2 = 1 names a circle, and the equation x=y2x = y^2 names a sideways parabola. In every case the set of points comes first; the equation is just one way to describe it.

A function is not a new kind of object. It is a relation with one extra property laid on top, and we lay it there for a definite reason. We want to be able to evaluate, to feed in a value and get a single answer back. A relation lets a point sit anywhere; a function insists that once you fix the input, the output is pinned down with no ambiguity. So a function is a relation in which each input is paired with exactly one output. Everything in this lesson comes from taking that sentence apart, and the first surprise is hiding in the word input.

The same curve, two different questions

Which variable is the input? Nothing in a set of points answers that; it is a choice you make. And the whole verdict “function or not” can flip depending on the choice. The cleanest example is the sideways parabola x=y2x = y^2.

Read it with xx as the input. Ask for the output at x=4x = 4: you need yy with y2=4y^2 = 4, and there are two, namely y=2y = 2 and y=−2y = -2. One input, two outputs, so with xx as the input this relation is not a function. Now read the identical set of points with yy as the input instead. Ask for the output at any value of yy: the rule x=y2x = y^2 hands back the single number y2y^2, one output every time. With yy as the input the very same relation is a function. The points on the page never moved. Only the question changed.

The relation x = y squared read with x as input and with y as inputLeft: a vertical line meets the sideways parabola at two points, so reading x as the input fails. Right: a horizontal line meets the same parabola once, so reading y as the input succeeds.reading x as the inputx = 2not a function of xreading y as the inputy = 1a function of y
One relation, the parabola x = y squared, read two ways. On the left x is the input, and the vertical line x = 2 meets the curve twice, so one input has two outputs and it is not a function of x. On the right y is the input, and every horizontal line meets the curve exactly once, so it is a function of y. The set of points is identical; only the choice of input differs.

This is why the vertical line test is worth restating carefully. It is often remembered as a fact about the shape of a curve, but it is not. It is the test for whether reading xx as the input produces a function, and it is exactly the picture of “one output per input.”

The vertical line test decides whether reading xx as the input gives a function#

A relation is a set of points, each written as a pair (input candidate, output candidate) with the first coordinate measured horizontally and the second vertically. Suppose we want to read xx as the input. Fix one input value aa. The points of the relation that use this input are exactly the ones whose first coordinate is aa. Those points are precisely the ones lying on the vertical line x=ax = a, since that line is by definition the set of all points with first coordinate aa. So the outputs the relation assigns to the input aa are the second coordinates of the points where the vertical line x=ax = a crosses the relation.

Now apply the definition of a function. Reading xx as the input gives a function exactly when each input has at most one output, which means each vertical line x=ax = a crosses the relation at most once. If instead some vertical line crossed it twice, those two crossings would share the input aa but carry two different outputs. An input carrying two outputs is exactly what the definition of a function forbids. The two statements are therefore equivalent, and that equivalence is the whole content of the test. Reading xx as the input is a function if and only if no vertical line meets the relation more than once.

Nothing in that argument singled out xx. An input value the relation never uses simply has no point on its vertical line. That absence is why a vertical line is allowed to miss the relation entirely; such an input is simply not in the domain.

Since nothing in the proof was special to xx, swap the roles of the two variables and the same argument runs word for word. Reading yy as the input is a function if and only if no horizontal line meets the relation more than once. The horizontal line test is not a second rule to memorize; it is the vertical line test asked about the other variable, applied to the very same points. Nothing about the graph has to move to ask this new question.

A different picture appears only if you go one step further and redraw the relation with yy placed on the horizontal axis, the normal spot for whichever variable is the input. That redrawing swaps the two coordinates of every point: (x,y)(x, y) becomes (y,x)(y, x). On the page, swapping every point’s coordinates like that reflects the whole graph across the line y=xy = x, and that reflection turns every vertical line into a horizontal one. So the new, redrawn graph passes the vertical line test exactly when the original graph passed the horizontal line test. This reflected, coordinate-swapped picture is the inverse relation. A later lesson will call it the inverse function exactly when the original relation was one-to-one, with its codomain taken to be its range: that is precisely the case just established, where the redrawn graph passes the vertical line test. So the question that opens this chapter, “can this rule be undone,” is underneath just the horizontal line test on the original graph, redrawn so the new input sits where an input belongs. We return to it in the inverse-functions lesson.

Two more relations are worth holding next to x=y2x = y^2. The unit circle x2+y2=1x^2 + y^2 = 1 fails both tests. At x=0x = 0 it has the two points (0,1)(0, 1) and (0,−1)(0, -1), and at y=0y = 0 it has (1,0)(1, 0) and (−1,0)(-1, 0), so the circle is a function of neither variable. The cubic y=x3y = x^3 passes both. Each xx gives the single output x3x^3, and each yy comes from the single input equal to its cube root, so the cubic is a function of both. “Function” really does live in the pairing of a curve with a choice of input, not in the curve alone.

Worked example 1 Is the circle x2+y2=25x^2 + y^2 = 25 a function?

The question is incomplete until we say a function of which variable, so test both readings.

Read xx as the input and solve for the output yy:

y2=25−x2⟹y=±25−x2.y^2 = 25 - x^2 \quad\Longrightarrow\quad y = \pm\sqrt{25 - x^2}.

At x=3x = 3 this gives y=±16=±4y = \pm\sqrt{16} = \pm 4, the two points (3,4)(3, 4) and (3,−4)(3, -4). One input, two outputs, so it is not a function of xx. A vertical line at x=3x = 3 would cut the circle twice.

Read yy as the input instead and solve for xx:

x=±25−y2.x = \pm\sqrt{25 - y^2}.

At y=3y = 3 this gives x=±4x = \pm 4, the points (4,3)(4, 3) and (−4,3)(-4, 3), so it is not a function of yy either. A circle is a function of neither variable, which fits the picture: no single output rule can follow a curve that doubles back on itself both horizontally and vertically.

Check your understanding

For the relation y2=x+1y^2 = x + 1, which statement is true?

Answer choices

The domain is part of the function, not a leftover

Here is the second idea, and it is easy to miss because in earlier courses it never came up. A function is not just a rule. Fully specified, it is three pieces of data at once: a domain, the set of allowed inputs, and a rule, telling you what to do to an input. The third piece is a codomain, a set you declare the outputs to fall inside. Change any one of the three and you have changed the function. The rule is the piece students notice, because it is the formula you can write down. The domain is just as much a part of the function, and forgetting it is the source of the trouble in this section.

In earlier courses “the domain” always meant one specific thing without anyone saying so: the largest set of inputs on which the formula returns a real number. That set has a name, the natural domain of the formula (also called the implied domain). It is a convention, the domain you assume when no other is stated. The natural domain is found the way you already know: throw out inputs that divide by zero or take an even root of a negative. For f(x)=1x−3f(x) = \dfrac{1}{x - 3} the natural domain is every real number except 33, and for g(x)=xg(x) = \sqrt{x} it is every real number greater than or equal to 00.

A declared domain is different. It is a domain stated outright as part of the function, and it can be smaller than the natural domain. Writing “let f(x)=x2f(x) = x^2 for x≥0x \ge 0” declares the domain to be the nonnegative numbers, even though the formula x2x^2 would happily accept every real number. The formula does not force this restriction; the author of the function chooses it, and it travels with the function from then on. A declared domain can only shrink the natural domain, never grow past it: you could not declare "x≥0x \ge 0" as the domain of f(x)=1x−3f(x) = \dfrac{1}{x - 3}, because that set still contains x=3x = 3, an input where the formula has no value. A legal declared domain has to leave out x=3x = 3 too, for instance ”x≥0x \ge 0 and x≠3x \ne 3”.

Intro algebra only ever computed the natural domain and called it “the” domain, which quietly assumed the domain is always read off the formula. It is not. The natural domain is a default, and a declared domain overrides it.

A declared domain does not have to come from algebra at all; it can come from what the numbers mean. Let C(n)=8nC(n) = 8n be the cost of nn tickets at 8 dollars each. The formula 8n8n is happy to accept any real number, but a ticket count must be a whole number and cannot be negative, so the situation declares the domain to be n=0,1,2,3,…n = 0, 1, 2, 3, \dots, a much smaller set than the formula alone would allow.

You have already felt the domain acting as real data. In the Solving Linear Equations lesson of Chapter 1, clearing denominators in xx−2=2x−2\dfrac{x}{x-2} = \dfrac{2}{x-2} produced the candidate x=2x = 2. That candidate had to be thrown out, because x=2x = 2 was never in the domain of the original equation. The exclusion did not come from the algebra after clearing; it came from the domain, which was fixed before any step was taken. That is the same lesson in a different costume: the domain is decided up front and constrains everything that follows.

Worked example 2 Find the natural domain of f(x)=x−4x−7f(x) = \dfrac{\sqrt{x - 4}}{x - 7}

No domain is declared, so find the natural domain: every real input for which the formula returns a real number. Two conditions must hold at once.

The square root requires a nonnegative inside, so

x−4≥0⟹x≥4.x - 4 \ge 0 \quad\Longrightarrow\quad x \ge 4.

The denominator cannot be zero, so

x−7≠0⟹x≠7.x - 7 \ne 0 \quad\Longrightarrow\quad x \ne 7.

Both must hold, so the natural domain is every real number with x≥4x \ge 4, except x=7x = 7. Notice that x=7x = 7 satisfies the root condition, so it is only the denominator that removes it, while every number below 44 is removed by the root. The domain is the overlap of the two requirements, not either one alone.

Check your understanding

What is the natural domain of h(x)=1x−5h(x) = \dfrac{1}{\sqrt{x - 5}}?

Answer choices

Same formula, different domain, different function

Because the domain is genuine data, two functions can share a formula letter for letter and still be different functions. This is not a technicality; it is the hinge the last lesson of this chapter turns on.

Compare f(x)=x2f(x) = x^2 with domain all real numbers against g(x)=x2g(x) = x^2 with domain x≥0x \ge 0. Same rule, different domains. They behave differently in a way that matters. The function ff is not one-to-one: f(−2)=4f(-2) = 4 and f(2)=4f(2) = 4, so two different inputs share an output, and the horizontal line y=4y = 4 meets its graph twice. The function gg is one-to-one: on the inputs x≥0x \ge 0, if g(a)=g(b)g(a) = g(b) then a2=b2a^2 = b^2, and since aa and bb are both nonnegative this forces a=ba = b. No horizontal line therefore meets the graph of gg more than once. Take each function’s codomain to be its range, so that “undone by a rule” is a fair question and not a mismatch of sets. Under that reading, gg can be undone by a rule and ff cannot, purely because their domains differ: one-to-one is exactly the property that lets every output be traced back to a single input.

The rule y = x squared on all reals versus on x greater than or equal to zeroLeft: the full parabola with a horizontal line cutting both arms. Right: the same parabola with the left arm dashed and removed, so the horizontal line meets the solid right arm only once.domain: all real xy = 2not one-to-onedomain: x greater or equal 0y = 2one-to-one
One formula, y = x squared, under two domains. On the left the domain is every real number, and the horizontal line y = 2 meets the graph twice, so the function is not one-to-one. On the right the domain is restricted to x greater than or equal to zero; the removed left half is dashed, the horizontal line now meets the graph once, and the function is one-to-one. Same rule, different domain, different function.

Worked example 3 Show that restricting the domain changes the function

Let f(x)=x2f(x) = x^2 on all real numbers and let g(x)=x2g(x) = x^2 on the domain x≥0x \ge 0. Decide whether each is one-to-one, and say why they are different functions.

For ff, look for two inputs with the same output. The inputs −3-3 and 33 both work:

f(−3)=9=f(3).f(-3) = 9 = f(3).

Two inputs, one output, so ff is not one-to-one.

For gg, the input −3-3 is no longer allowed, because the domain is x≥0x \ge 0. Take any allowed inputs a,b≥0a, b \ge 0 with g(a)=g(b)g(a) = g(b):

a2=b2⟹a2−b2=0⟹(a−b)(a+b)=0.a^2 = b^2 \quad\Longrightarrow\quad a^2 - b^2 = 0 \quad\Longrightarrow\quad (a - b)(a + b) = 0.

Then a=ba = b or a=−ba = -b, and since both are nonnegative, a=−ba = -b can only happen when a=b=0a = b = 0. Either way a=ba = b, so gg is one-to-one. The two functions share every letter of their formula yet differ in a real property, one-to-oneness, so they are genuinely different functions. The domain, not the formula, made the difference, and restricting a domain to gain one-to-oneness, with the codomain then taken to be the range, is exactly how the inverse-functions lesson will earn its inverses honestly.

Check your understanding

Let f(x)=x2f(x) = x^2 with domain all real numbers and g(x)=x2g(x) = x^2 with domain x≥0x \ge 0. Which statement is correct?

Answer choices

Range and codomain

The output side has its own pair of words, and keeping them apart avoids a common muddle. The codomain is the set you declare the outputs to live in when you set the function up. The codomain is often just “the real numbers,” for lack of a reason to say anything smaller. The range is sharper: it is the set of outputs the function actually produces, every value f(x)f(x) hit by some input in the domain.

The range always sits inside the codomain. The two sets need not be equal, because declaring a set for the outputs to live in does not promise that every element of it gets used. Take f(x)=x2f(x) = x^2 on all real numbers with codomain the real numbers. Every output is a square, and a square is never negative, so the range sits inside the nonnegative numbers. It is not smaller than that either: for any target y≥0y \ge 0, the real input x=yx = \sqrt{y} gives f(x)=yf(x) = y, so every nonnegative number really is produced. The range is exactly that nonnegative set, a strict part of the real-number codomain: the negative numbers sit in the codomain but are never outputs. When a problem asks for “the range,” it is asking what the function really hits. Answering that takes a moment’s thought about the rule, not just a glance at where you declared the outputs.

Check your understanding

Let f(x)=x2f(x) = x^2 have domain {−2,−1,0,1,2}\{-2, -1, 0, 1, 2\} and declared codomain the real numbers. What is the range of ff?

Answer choices

Worked example 4 Find the range of f(x)=x2+1f(x) = x^2 + 1 on all real numbers

The range is the set of values the output can actually take, so start from what the rule can reach.

The term x2x^2 is a square, so it is never negative:

x2≥0⟹x2+1≥1.x^2 \ge 0 \quad\Longrightarrow\quad x^2 + 1 \ge 1.

Every output is therefore at least 11, and the value 11 itself is reached, at x=0x = 0. To see that every larger number is reached too, work backward: given any target output y≥1y \ge 1, solve x2+1=yx^2 + 1 = y for xx, which gives x=y−1x = \sqrt{y - 1}, a real number because y−1≥0y - 1 \ge 0. Plugging that xx back into the rule returns exactly yy, so every y≥1y \ge 1 really is an output. The range is all real numbers greater than or equal to 11. If this function were set up with codomain “all real numbers,” the range would be a strict part of it, since nothing below 11 is ever output.

A bound can belong to the range or sit just outside it, and the two cases look alike until you check. Take f(x)=1x2+1f(x) = \dfrac{1}{x^2 + 1} on all real numbers. The denominator is at least 11, so every output lies in 0<f(x)≤10 < f(x) \le 1. The upper bound 11 is attained: it is the genuine output at x=0x = 0, since f(0)=1f(0) = 1. Every value strictly between 00 and 11 is attained too: given a target 0<y≤10 < y \le 1, solving 1x2+1=y\dfrac{1}{x^2+1} = y for xx gives x=1y−1x = \sqrt{\dfrac{1}{y} - 1}, a real number because y≤1y \le 1 keeps 1y−1\dfrac{1}{y} - 1 nonnegative. The lower bound 00 is only approached: as xx grows the outputs shrink toward 00, but a ratio of positive numbers is never 00, so no input ever produces it. A value belongs to the range exactly when some input actually produces it. That is why the range is 0<y≤10 < y \le 1, closed at the attained end and open at the approached end. Deciding this is never automatic: for each candidate bound you check whether it is a real output or only a value the outputs crowd against.

The rule and domain as a set of ordered pairs

Both ideas of this lesson fold into one description. A function’s rule and domain together are a set of ordered pairs in which no two different pairs share the same first coordinate. Declaring a codomain on top of those pairs completes the function. Read that description once for each idea.

Read for the first idea: which variable you treat as the input decides which pairs you write down. If xx is the input, use the pairs (x,y)(x, y) exactly as the relation gives them, and the rule against a repeated first coordinate is precisely the vertical line test. If yy is the input instead, swap the two entries of every pair to get (y,x)(y, x); whether that new set of pairs is again a function is precisely the horizontal line test, and the swapped set is the seed of the inverse.

Read for the second idea, the domain is not computed from anything. It is simply the set of first coordinates that appear among the pairs, so it is built in from the start; include different pairs and you have a different function. The range, in the same breath, is the set of second coordinates that appear. So the pairs carry the rule, the domain, and the range at once. The one piece they do not carry is the codomain, the larger set you declare the outputs to live in. So you state the codomain separately, and the function is then complete. Two ideas, one object.

Common mistakes

Practice

Multiple Choice Questions (MCQ)

Progressively harder sets of questions. Each opens on its own page.

Core practice

Practice problems at the level of the course, to be worked out on paper. Hints one at a time, then the answer or the full worked solution, with your progress kept in this browser.

Core practice Work it out on paper 10 problems Start →
More practice (optional)

Extra sets, as hard as the Challenge set. Each one opens on its own page.

More resources (optional)

Other explanations of this lesson, if you want a second take.

A bit of history (optional)

Ask a mathematician in 1740 what a function was, and the answer was a formula.

Leonhard Euler, a Swiss mathematician, wrote that down in 1748. A function, he said, is an analytic expression: one formula, built from a variable and some constants. On that view the formula was the function. Its domain is then whatever the formula allows, and nothing at all is left for you to choose.

That view did not last the century. Peter Gustav Lejeune Dirichlet, a German mathematician, replaced it in 1837. His version asks for no formula at all. To each value of the input, within a stated domain, there corresponds one definite output. That is the whole of it. The pairing is the function, and the domain of allowed inputs is announced rather than computed.

Dirichlet had already built the example that forced the change. Take the rule that returns one fixed number at every fraction, and a different fixed number everywhere else. It jumps between the two inside every interval, however short. No formula of Euler’s kind can capture that. Yet each input still gets exactly one output, so it is a function.

So the pairing comes first, and a formula is only one way to name it. That is why this lesson treats the domain as data, not as a leftover. It is also why one set of points can be a function of one variable but not the other.