math.wiki
Functions › Combining and composing functions › Evaluating a composition from numbers, tables and graphs
Open on the map
Algebra 2

Evaluating a composition from numbers, tables and graphs

The output of one function is exactly what a second function needs as its input. How do you get from the first input to the final output?

Where you are 5 in Combining and composing functions

When you reach for it

Many quantities depend on something that itself depends on something else. The height of a weather balloon depends on how long it has been rising, and the temperature of the air around it depends on its height. To know the temperature after 10 minutes you have to go through the height: time gives height, and height gives temperature. Two functions are chained, and the output of the first is the input of the second.

Running a number through one function and feeding the result straight into another is called composing the two functions, and the chained function is their composition. This lesson is about finding a composition’s value at one particular number, when the two functions are given as formulas, as tables or as graphs. Each step is something you can already do: evaluating a function at a number from its formula, or reading a value off a graph. What is new is only the order of the steps and where the first answer goes.

Reach for it whenever a function’s brackets hold another function, as in f(g(3)), whenever you see the small circle in (f \circ g)(3), and whenever a problem happens in two stages, the result of the first being what the second works on.

The procedure

Inside first

Let f(x) = 3x - 7 and g(x) = 10 - x^2. The expression f(g(3)) asks for f evaluated at the number g(3). The function f cannot do anything until it has a number to act on, and that number is g(3), so g(3) is found first:

g(3) = 10 - 3^2 = 10 - 9 = 1

The inner bracket is now the number 1, so f(g(3)) is f(1):

f(g(3)) = f(1) = 3(1) - 7 = -4

Each step was an ordinary evaluation, a number substituted into one formula. The brackets are worked from the inside out for the same reason as in arithmetic, where 2(5 - 1) needs 5 - 1 before anything can be doubled.

The order of the letters matters. In g(f(3)) the function f is inside, so it acts first: f(3) = 3(3) - 7 = 2, and then

g(f(3)) = g(2) = 10 - 2^2 = 6

That is 6, not -4.

3
g
g(3) = 1
f
f(g(3)) = -4
3
f
f(3) = 2
g
g(f(3)) = 6
Figure 1The same two machines in the two possible orders. For f(x) = 3x - 7 and g(x) = 10 - x^2, the input 3 comes out as -4 one way and as 6 the other.

Think of each function as a machine: a number goes in and a number comes out. A composition is two machines in a row, with the output of the first sent straight into the second. Swapping the machines changes the result because each one does something different to whatever it receives: g squares and subtracts from 10, while f triples and takes away 7. Squaring 3 and squaring 2 are very different events.

The circle notation

The composition gets a name of its own. For any two functions f and g,

(f \circ g)(x) = f(g(x))

read “f composed with g”, or “f of g”. The function written on the right, next to the input, acts first. Reading f \circ g from right to left is the same as reading f(g(x)) from the inside out. So

\begin{aligned} (f \circ g)(3) &= f(g(3)) = -4 \\ (g \circ f)(3) &= g(f(3)) = 6 \end{aligned}

The small circle is not multiplication. The product (fg)(3) of two functions multiplies their two outputs at the same input: (fg)(3) = f(3)\,g(3) = 2 \cdot 1 = 2. The same two functions at the same input have now given three different numbers, -4, 6 and 2, and the notation is what tells them apart.

A function can also be composed with itself, so that its output goes back into it:

(f \circ f)(3) = f(f(3)) = f(2) = 3(2) - 7 = -1

From a table

When the functions are given by a table, there is no formula to substitute into, and each evaluation becomes a lookup. Look up the inner function at the given input. Then find that output in the input row of the table and read the outer function there. The output of the first lookup is not an answer yet; it is the address of the second lookup. Example 3 works through it.

From a graph

On a graph, the value of a function at an input is a height: go from the input on the x-axis straight up or down to the graph and read how high it is. A composition reads two graphs in turn. The height read on the inner graph becomes an input, so it is looked for on the x-axis of the outer graph, not on its y-axis.

The two functions u and w below are used for the rest of the lesson. The graph of u is made of straight pieces through grid corners, and w is the parabola w(x) = (x - 2)^2 - 3, drawn only from x = -1 to x = 5.

x y x y −4 −3 −2 −1 1 2 3 4 5 −4 −3 −2 −1 1 2 3 4 5 6 −2 −1 1 2 3 4 5 6 −4 −3 −2 −1 1 2 3 4 5 6
y = u(x)
y = w(x)
Figure 2The functions u and w, used in the procedure, in Examples 4 and 7 and in Exercises 15 to 19. Each is defined only where its graph is drawn.

To find w(u(1)), start on the graph of u, the inner function. Go up from 1 on the x-axis to the line, and read the height: u(1) = 2. Now carry that 2 to the other graph and find it on the x-axis. Go down from 2 to the parabola, which reaches its lowest point there, and read the height: w(2) = -3. So w(u(1)) = -3. The formula agrees: w(2) = (2 - 2)^2 - 3 = -3.

x y x y −4 −3 −2 −1 1 2 3 4 5 −4 −3 −2 −1 1 2 3 4 5 6 −2 −1 1 2 3 4 5 6 −4 −3 −2 −1 1 2 3 4 5 6
y = u(x)
y = w(x)
Figure 3Evaluating w(u(1)). The height read on the first graph, 2, becomes the input on the second graph’s x-axis.

When the chain breaks

(f \circ g)(a) has a value only when both steps do: a has to be an input g accepts, and g(a) has to be an input f accepts. The second condition can fail even when a itself is a perfectly good number. In the graphs above, u(-4) = -2, but w is drawn only from x = -1 to x = 5, so w(-2) is not given and (w \circ u)(-4) has no value. Collecting every input for which both steps work gives the domain of the composition.

Worked examples

Example 1

Both orders, and a function composed with itself

Let p(x) = 2x^2 - 3x and s(x) = 5 - 2x. Find (a) p(s(4)), (b) s(p(4)) and (c) (s \circ s)(4).

Solution

(a) The inner function is s, so start there: s(4) = 5 - 2(4) = -3. Then p(s(4)) = p(-3). Put the -3 in brackets when substituting, because the whole input is squared, sign and all:

p(-3) = 2(-3)^2 - 3(-3) = 2(9) + 9 = 27

(b) Now p is inside: p(4) = 2(16) - 3(4) = 32 - 12 = 20. Then s(p(4)) = s(20) = 5 - 2(20) = -35. The two orders give 27 and -35.

(c) (s \circ s)(4) = s(s(4)). The inner value is s(4) = -3 from part (a), and then

s(-3) = 5 - 2(-3) = 5 + 6 = 11

so (s \circ s)(4) = 11.

Example 2

Roots, fractions and inputs that fail

Let \displaystyle r(x) = \sqrt{x + 7} and v(x) = \dfrac{12}{x - 1}. Find each value, or explain why there is none: (a) (r \circ v)(13), (b) (v \circ r)(2), (c) (v \circ r)(-6), (d) (r \circ v)(0).

Solution

(a) In r \circ v the function on the right, v, acts first: \displaystyle v(13) = \frac{12}{12} = 1. Then \displaystyle r(1) = \sqrt{8}, and since 8 = 4 \cdot 2, \displaystyle \sqrt{8} = \sqrt{4}\,\sqrt{2} = 2\sqrt{2}. So \displaystyle (r \circ v)(13) = 2\sqrt{2}.

(b) Now r acts first: \displaystyle r(2) = \sqrt{9} = 3. Then \displaystyle v(3) = \frac{12}{3 - 1} = 6. So (v \circ r)(2) = 6.

(c) \displaystyle r(-6) = \sqrt{1} = 1, which is fine. But then \displaystyle v(1) = \frac{12}{0}, and division by zero has no value. So (v \circ r)(-6) does not exist. The input -6 was acceptable to r; the trouble is that r turned it into 1, the one number v cannot take.

(d) \displaystyle v(0) = \frac{12}{0 - 1} = -12. Then \displaystyle r(-12) = \sqrt{-12 + 7} = \sqrt{-5}, and no real number squares to -5. So (r \circ v)(0) has no real value.

Parts (c) and (d) failed at the second step. A composition can also fail at the first: (r \circ v)(1) needs \displaystyle v(1) = \frac{12}{0}, and the chain never starts.

Example 3

Compositions from a table

The functions h and k are given by this table.

x012345
h(x)350421
k(x)245106

Find (a) h(k(1)), (b) k(h(1)), (c) (h \circ h)(0) and (d) (h \circ k)(5). Then make a table of (h \circ k)(x) for every input the table allows.

Solution

(a) Inside first. In the column x = 1, the k row gives k(1) = 4. Now 4 is an input: in the column x = 4, the h row gives h(4) = 2. So h(k(1)) = 2.

(b) h(1) = 5, read in column 1. Then column 5, row k: k(5) = 6. So k(h(1)) = 6.

(c) (h \circ h)(0) = h(h(0)). Column 0, row h: h(0) = 3. Column 3, row h again: h(3) = 4. So (h \circ h)(0) = 4.

(d) k(5) = 6, but there is no column for x = 6, so the table does not give h(6). The table says nothing about (h \circ k)(5), and the honest answer is that it cannot be found from this information. It is not 0, and it is not 6.

For the whole table, do the same two lookups in every column. Each entry of the middle row is used as an address in the h row:

x012345
k(x)245106
h(k(x))02153not given

For instance k(2) = 5 and h(5) = 1, so (h \circ k)(2) = 1.

Example 4

Compositions from two graphs

Use the graphs of u and w in the procedure. Find (a) (w \circ u)(-1), (b) u(w(0)), (c) (u \circ w)(5) and (d) (w \circ u)(4).

Solution

(a) u acts first. At x = -1 the graph of u is at its highest corner, height 4, so u(-1) = 4. On the graph of w, go up from 4 on the x-axis: the parabola is at height 1. So (w \circ u)(-1) = w(4) = 1.

(b) Now w is inside. The parabola crosses the y-axis at height 1, so w(0) = 1. On the graph of u, at x = 1 the line is at height 2. So u(w(0)) = u(1) = 2.

(c) w(5) = 6, the right end of the parabola. But the graph of u stops at x = 5, so u(6) is not given and (u \circ w)(5) has no value.

(d) x = 4 lies on the last piece of u, which runs from (3, 0) to (5, 2), rising 1 for each 1 across. So u(4) = 1. Then w(1) = -2, read off the parabola. So (w \circ u)(4) = -2.

Check the readings of w with its formula: w(4) = 2^2 - 3 = 1, w(0) = (-2)^2 - 3 = 1 and w(1) = (-1)^2 - 3 = -2.

Example 5

A weather balloon

A weather balloon rises at a steady 200 meters per minute, so its height after t minutes is A(t) = 200t meters, for 0 \le t \le 20. In a simple model, the air temperature at a height of a meters is T(a) = 15 - 0.006a degrees Celsius.

(a) Find (T \circ A)(10) and say what it means. (b) Explain why (A \circ T)(10) means nothing here. (c) After how many minutes is the air around the balloon at 0 degrees?

Solution

(a) A acts first: A(10) = 200(10) = 2000. Then T(2000) = 15 - 0.006(2000) = 15 - 12 = 3. So (T \circ A)(10) = 3: after 10 minutes the balloon is 2000 meters up, where the air is 3 degrees.

(b) (A \circ T)(10) = A(T(10)). Here T(10) = 14.94 is a temperature in degrees, and A takes a time in minutes. The arithmetic 200(14.94) can be done, but it treats 14.94 degrees as 14.94 minutes, so the result describes nothing. In a real situation the output of the inner function has to be the kind of quantity the outer function takes in.

(c) Now the final output is known and the input is wanted, so work from the outside in. The last function applied was T, so undo it first: T(a) = 0 means 15 - 0.006a = 0, so a = 2500 meters. Then undo A: 200t = 2500 gives t = 12.5 minutes, which is inside the allowed 0 \le t \le 20. Check: A(12.5) = 2500 and T(2500) = 15 - 15 = 0.

Example 6

Which order is cheaper

A shop takes 20\% off every price, D(p) = 0.8p, and a coupon takes 5 dollars off, C(p) = p - 5, where p is a price in dollars. A jacket costs 40 dollars.

(a) Find the price if the coupon is used first and the discount taken after, D(C(40)). (b) Find the price if the discount comes first, C(D(40)). (c) Show that, whatever the price p (at least 5 dollars), the second order is exactly 1 dollar cheaper.

Solution

(a) C(40) = 35, then D(35) = 0.8(35) = 28. The jacket costs 28 dollars.

(b) D(40) = 0.8(40) = 32, then C(32) = 27. The jacket costs 27 dollars.

(c) Do the same steps with p in place of 40. Coupon first: D(C(p)) = 0.8(p - 5) = 0.8p - 4, by the distributive property. Discount first: C(D(p)) = 0.8p - 5. The difference is

(0.8p - 4) - (0.8p - 5) = 1

whatever p is. The reason is visible in the first line: when the coupon goes first, the 20\% discount also shrinks the coupon, from 5 dollars to 0.8(5) = 4.

Example 7

Working backwards on the graphs

Using the graphs of u and w, find every x with w(u(x)) = -2.

Solution

The final output is known, so start with the outer function, w. Which inputs does w send to -2? The horizontal level -2 meets the parabola at x = 1 and x = 3, since w(1) = w(3) = -2. So u(x) must be 1 or 3, and both cases have to be followed.

u(x) = 1. The level 1 meets the graph of u three times. On the first piece, which rises 2 for each 1 across, the height goes from 0 at x = -3 to 2 at x = -2, so it is 1 halfway, at x = -2.5. On the falling piece, u(2) = 1. On the last piece, u(4) = 1.

u(x) = 3. On the first piece the height goes from 2 at x = -2 to 4 at x = -1, so it is 3 halfway, at x = -1.5. On the falling piece, u(0) = 3. The last piece rises only to 2, so it never reaches 3.

So w(u(x)) = -2 at five inputs: x = -2.5, -1.5, 0, 2 and 4. Check one of them: u(-1.5) = 3 and w(3) = (3 - 2)^2 - 3 = -2.

The composition reaches -2 more often than either function reaches any single value. Working backwards branched twice: w sends two inputs to -2, and u reaches those two inputs three times and twice, five inputs in all.

Boundaries

Both steps must work. (f \circ g)(a) needs a in the domain of g, and then g(a) in the domain of f. If either fails there is no value, as in Example 2 (c) and (d). The second failure is easy to miss, because a itself looks harmless.

The order is part of the question. f \circ g and g \circ f are in general different functions, and (f \circ g)(a) and (g \circ f)(a) are in general different numbers. Some pairs do give the same value either way (Exercise 23 has one), but that is a fact about those two functions, never something to assume.

The circle is not a product. (f \circ g)(a) = f(g(a)), while (fg)(a) = f(a)\,g(a).

A table or graph gives only what it shows. If the inner output is not among the inputs listed, or lies outside the part of the graph that is drawn, the composition has no value from that information. A missing entry is not zero. And a value read off a graph is only as exact as the picture; the graphs here pass through grid corners so that the readings are exact.

In context, the quantities must match. The output of the inner function has to be the kind of quantity the outer function takes in: minutes into a function of time, meters into a function of height. Otherwise the arithmetic produces a number that means nothing.

Working backwards undoes the outer function first, and may branch. To solve f(g(x)) = c, find every input f sends to c, then every x that g sends to each of those. Either step may have several answers, or none.

Where this goes next

Evaluating at one number at a time is enough for a table or a graph, but with formulas you can do the substitution once for every input. Put x in place of 3 in the opening example: f(g(x)) = 3(10 - x^2) - 7 = 23 - 3x^2, and at x = 3 this gives 23 - 27 = -4, as before. That is composing functions algebraically, and it is also the reverse skill of spotting a complicated function as a simpler one inside another. The question of exactly which inputs survive both steps is the domain of a composition.

Composition is the language of undoing. Two functions are inverses when each one undoes the other, which says that f(g(x)) = x for every input: the composition hands back exactly what it was given. A function composed with itself over and over, as in Exercise 22, is the same move as a recursive formula, where each term is made from the one before.

In calculus, the rate of change of a composition is found by multiplying the rates of its two steps, which is the chain rule. The balloon already shows it: height grows by 200 meters a minute and temperature falls by 0.006 degrees a meter, so (T \circ A)(t) = 15 - 1.2t, and the temperature falls by 200 \cdot 0.006 = 1.2 degrees a minute.

Exercises

From formulas

Let a(x) = 4x + 1 and b(x) = x^2 - 3x.

  1. Find a(b(2)).
  2. Find b(a(2)).
  3. Find (a \circ a)(-1).

Roots, fractions and failures

Let \displaystyle c(x) = \sqrt{2x + 1} and d(x) = x^2 - 8.

  1. Find (c \circ d)(4).
  2. Find (d \circ c)(12).

Let j(x) = \dfrac{6}{x + 2} and n(x) = 2 - x^2.

  1. Find (j \circ n)(1).
  2. Find (n \circ j)(1).
  3. Find (j \circ n)(2), or explain why it does not exist.

From a table

x-2-10123
P(x)13-120-2
Q(x)023-214
  1. Find P(Q(0)).
  2. Find Q(P(0)).
  3. Find (P \circ P)(1).
  4. Find (Q \circ P)(2).
  5. Find (P \circ Q)(3), or explain why the table cannot give it.
  6. Find every x in the table with Q(P(x)) = 1.

From graphs

Use the graphs of u and w in the procedure.

  1. Find (u \circ w)(1).
  2. Find (w \circ u)(3).
  3. Find (u \circ u)(-3).
  4. Find (w \circ w)(4).
  5. Find (w \circ u)(-4), or explain why it has no value.

In context

  1. A car uses F(d) = 0.08d liters of fuel to drive d kilometers, and fuel costs C(L) = 1.6L dollars for L liters. Find (C \circ F)(250) and say what it means.
  2. A sweater is marked 60 dollars. A sale takes 25\% off, D(p) = 0.75p, and a coupon takes 10 dollars off, C(p) = p - 10. Find D(C(60)) and C(D(60)), and say which order is cheaper for the customer.
  3. Let \displaystyle H(x) = \frac{x}{2} + 4. Find (H \circ H \circ H)(0), meaning H(H(H(0))). Then find the number x with H(x) = x.

Reasoning

  1. Let f(x) = x + 2 and g(x) = x + 5. Show that (f \circ g)(a) = (g \circ f)(a) for every number a, and explain why the order makes no difference for these two functions.
  2. Explain how (f \circ g)(a) can fail to exist even though a is in the domain of g. Use Example 2 to illustrate.
  3. To solve f(g(x)) = c, you undo f before you undo g. Explain why that order is forced, using the balloon of Example 5.
Answers
  1. -7. b(2) = 4 - 6 = -2, then a(-2) = 4(-2) + 1 = -7.
  2. 54. a(2) = 9, then b(9) = 81 - 27 = 54.
  3. -11. a(-1) = -3, then a(-3) = -12 + 1 = -11.
  4. \displaystyle \sqrt{17}. d(4) = 16 - 8 = 8, then \displaystyle c(8) = \sqrt{16 + 1} = \sqrt{17}.
  5. 17. \displaystyle c(12) = \sqrt{25} = 5, then d(5) = 25 - 8 = 17.
  6. 2. n(1) = 2 - 1 = 1, then \displaystyle j(1) = \frac{6}{3} = 2.
  7. -2. j(1) = 2, then n(2) = 2 - 4 = -2.
  8. It does not exist. n(2) = 2 - 4 = -2, and \displaystyle j(-2) = \frac{6}{0} is undefined: 2 is a fine input for n, but n sends it to the one number j cannot take.
  9. -2. Q(0) = 3, then P(3) = -2.
  10. 2. P(0) = -1, then Q(-1) = 2.
  11. 0. P(1) = 2, then P(2) = 0.
  12. 3. P(2) = 0, then Q(0) = 3.
  13. The table cannot give it. Q(3) = 4, and there is no column for x = 4, so P(4) is not given.
  14. Only x = 1. Going column by column, Q(P(x)) is -2, 4, 2, 1, 3, 0 for x = -2, -1, 0, 1, 2, 3; for instance P(1) = 2 and Q(2) = 1.
  15. 2. w(1) = -2, then on the first piece of u, u(-2) = 2.
  16. 1. u(3) = 0, then w(0) = 1.
  17. 3. u(-3) = 0, then u(0) = 3.
  18. -2. w(4) = 1, then w(1) = -2.
  19. It has no value. u(-4) = -2, but w is drawn only from x = -1 to x = 5, so w(-2) is not given.
  20. 32. F(250) = 20 liters, and C(20) = 32: driving 250 kilometers uses 32 dollars of fuel.
  21. D(C(60)) = 37.5 and C(D(60)) = 35, so taking the discount first and the coupon after is cheaper. C(60) = 50 and 0.75(50) = 37.5; D(60) = 45 and 45 - 10 = 35.
  22. (H \circ H \circ H)(0) = 7, and H(x) = x at x = 8. H(0) = 4, H(4) = 6, H(6) = 7. Solving \displaystyle \frac{x}{2} + 4 = x gives \displaystyle \frac{x}{2} = 4. Each further step halves the distance to 8, since \displaystyle 8 - H(x) = \frac{8 - x}{2}.
  23. Both are a + 7: f(g(a)) = (a + 5) + 2 and g(f(a)) = (a + 2) + 5. Each function only adds a number, and additions can be done in either order (the commutative and associative properties of addition), so the order of the two machines does not matter.
  24. The first step can work and the second fail: g(a) exists but is not in the domain of f. In Example 2 (c), -6 is a fine input for r, but r(-6) = 1 and \displaystyle v(1) = \frac{12}{0} is undefined; in (d), v(0) = -12 and \displaystyle r(-12) = \sqrt{-5} is not real.
  25. In T(A(t)) = 0 the only thing known is the output of T, the last step. From it you can find the height a with T(a) = 0, which is 2500; nothing can be said about t until that height is known, because A is what turns t into a height. Then A(t) = 2500 gives t = 12.5. The steps are undone in the reverse of the order they were done.
unattributed · CC-BY-SA-4.0