Skip to content
Family Table Math
Auto

Composition of Functions

Sometimes the output of one function becomes the input of another. The distance you drive depends on time, the fuel you burn depends on distance, and the cost depends on the fuel. Chaining functions like this is called composition, and it gives you a single function that goes straight from the first input to the final output.

The composition of ff and gg is

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

Read it from the inside out: first apply gg to xx, then apply ff to the result. Picture two function machines in a row. The number xx goes into machine gg, and whatever comes out goes straight into machine ff.

x  →  g    g(x)  →  f    f(g(x))x \;\xrightarrow{\;g\;}\; g(x) \;\xrightarrow{\;f\;}\; f\big(g(x)\big)

For example, if g(x)=x+1g(x) = x + 1 and f(x)=x2f(x) = x^2, then f(g(3))=f(4)=16f(g(3)) = f(4) = 16.

In general, f(g(x))≠g(f(x))f(g(x)) \ne g(f(x)). With the same functions, g(f(3))=g(9)=10g(f(3)) = g(9) = 10, not 1616. “Add 11, then square” is a different process from “square, then add 11”. Occasionally the two orders do agree (for example, a function and its inverse), but you can never assume it.

  • From tables: find g(x)g(x) in the gg table, then look up that number in the ff table.
  • From graphs: read g(x)g(x) from the graph of gg (go up or down from xx to the graph). Then use that output as the new input on the graph of ff.
  • From equations: substitute the whole expression for g(x)g(x) in place of every xx in f(x)f(x). Use brackets.
Graphs of y = f(x), a parabola with vertex (0, -2) through (1, -1), (2, 2) and (-2, 2), and y = g(x), a line with slope -1 through (0, 3) and (3, 0). −3 −2 −1 1 2 3 4 −2 −1 1 2 3 4 5 6 y = f(x) y = g(x)
Reading compositions from graphs: here f(x)=x2−2f(x) = x^2 - 2 and g(x)=−x+3g(x) = -x + 3.

To find f(g(1))f(g(1)) from the graphs above: the line gives g(1)=2g(1) = 2, and then the parabola gives f(2)=2f(2) = 2. So f(g(1))=2f(g(1)) = 2. In the other order, f(1)=−1f(1) = -1, and then g(−1)=4g(-1) = 4, so g(f(1))=4g(f(1)) = 4.

xx is in the domain of f∘gf \circ g when both of these are true:

  1. xx is in the domain of gg (so g(x)g(x) exists), and
  2. g(x)g(x) is in the domain of ff (so ff can accept it).

Find the domain from these conditions, not just from the simplified formula, which can hide a restriction (Example 3 shows how). For the range, think about which values of g(x)g(x) actually get fed into ff, and what ff does to them.

Going backwards, you can often split a complicated function into an “inside” and an “outside” function. For h(x)=(5x−2)3h(x) = (5x - 2)^3, the inside is g(x)=5x−2g(x) = 5x - 2 and the outside is f(x)=x3f(x) = x^3, so h(x)=f(g(x))h(x) = f(g(x)). Decomposing is useful for seeing how a function was built, and you’ll use it constantly in calculus.

Use the tables to evaluate f(g(0))f(g(0)), g(f(0))g(f(0)), f(g(3))f(g(3)), g(f(3))g(f(3)) and f(f(4))f(f(4)).

xx0011223344
f(x)f(x)3344002211
g(x)g(x)1133440022

Solution. Work from the inside out each time.

  • f(g(0))f(g(0)): g(0)=1g(0) = 1, then f(1)=4f(1) = 4. So f(g(0))=4f(g(0)) = 4.
  • g(f(0))g(f(0)): f(0)=3f(0) = 3, then g(3)=0g(3) = 0. So g(f(0))=0g(f(0)) = 0.
  • f(g(3))f(g(3)): g(3)=0g(3) = 0, then f(0)=3f(0) = 3. So f(g(3))=3f(g(3)) = 3.
  • g(f(3))g(f(3)): f(3)=2f(3) = 2, then g(2)=4g(2) = 4. So g(f(3))=4g(f(3)) = 4.
  • f(f(4))f(f(4)): f(4)=1f(4) = 1, then f(1)=4f(1) = 4. So f(f(4))=4f(f(4)) = 4.

The first two show that changing the order changes the answer: f(g(0))=4f(g(0)) = 4 but g(f(0))=0g(f(0)) = 0.

Let f(x)=x2+1f(x) = x^2 + 1 and g(x)=3x−2g(x) = 3x - 2. Find f(g(x))f(g(x)) and g(f(x))g(f(x)).

Solution. For f(g(x))f(g(x)), replace the xx in ff with the whole expression (3x−2)(3x - 2):

f(g(x))=(3x−2)2+1=9x2−12x+4+1=9x2−12x+5\begin{aligned} f\big(g(x)\big) &= (3x - 2)^2 + 1 \\ &= 9x^2 - 12x + 4 + 1 \\ &= 9x^2 - 12x + 5 \end{aligned}

For g(f(x))g(f(x)), replace the xx in gg with (x2+1)(x^2 + 1):

g(f(x))=3(x2+1)−2=3x2+1g\big(f(x)\big) = 3(x^2 + 1) - 2 = 3x^2 + 1

The results are different functions.

Check with x=1x = 1: g(1)=1g(1) = 1 and f(1)=2f(1) = 2, and the formula gives 9−12+5=29 - 12 + 5 = 2. ✓ Also f(1)=2f(1) = 2 and g(2)=4g(2) = 4, and the formula gives 3+1=43 + 1 = 4. ✓

Let f(x)=xf(x) = \sqrt{x} and g(x)=4−x2g(x) = 4 - x^2. Find f(g(x))f(g(x)) and g(f(x))g(f(x)), and state the domain and range of each.

Solution.

f(g(x))f(g(x)).

f(g(x))=4−x2f\big(g(x)\big) = \sqrt{4 - x^2}

gg accepts every real number, but ff can only take inputs that are ≥0\ge 0. So we need 4−x2≥04 - x^2 \ge 0, which means x2≤4x^2 \le 4, or −2≤x≤2-2 \le x \le 2.

For these xx-values, 4−x24 - x^2 goes from 00 (at x=±2x = \pm 2) up to 44 (at x=0x = 0). Taking square roots gives values from 00 to 22.

Domain: {x∈R∣−2≤x≤2}Range: {y∈R∣0≤y≤2}\text{Domain: } \{x \in \mathbb{R} \mid -2 \le x \le 2\} \qquad \text{Range: } \{y \in \mathbb{R} \mid 0 \le y \le 2\}

(The graph is the top half of a circle with radius 22.)

g(f(x))g(f(x)).

g(f(x))=4−(x)2=4−xg\big(f(x)\big) = 4 - \left(\sqrt{x}\right)^2 = 4 - x

It looks like a line, but the first step is x\sqrt{x}, which needs x≥0x \ge 0. So the domain is {x∈R∣x≥0}\{x \in \mathbb{R} \mid x \ge 0\}, and the graph is only the part of y=4−xy = 4 - x starting at (0,4)(0, 4). As xx grows from 00, 4−x4 - x falls from 44, so the range is {y∈R∣y≤4}\{y \in \mathbb{R} \mid y \le 4\}.

Example 4: Fuel cost as a function of time

Section titled “Example 4: Fuel cost as a function of time”

A delivery van drives on the highway at 100100 km/h, so after tt hours it has gone d(t)=100td(t) = 100t km. It uses 7.57.5 L of fuel per 100100 km, so F(d)=0.075dF(d) = 0.075d litres for dd kilometres. Fuel costs $1.60 per litre, so C(F)=1.60FC(F) = 1.60F dollars.

  • (a) Find C(F(d(t)))C(F(d(t))) and explain what it means.
  • (b) How much does the fuel cost for a 4.54.5-hour drive?

Solution.

(a) Work from the inside out:

F(d(t))=0.075(100t)=7.5tC(F(d(t)))=1.60(7.5t)=12t\begin{aligned} F\big(d(t)\big) &= 0.075(100t) = 7.5t \\ C\big(F(d(t))\big) &= 1.60(7.5t) = 12t \end{aligned}

C(F(d(t)))=12tC(F(d(t))) = 12t is the fuel cost, in dollars, of driving for tt hours: the van burns $12 of fuel per hour. Composition skipped the middle steps and went straight from time to cost.

(b) 12(4.5)=5412(4.5) = 54, so the fuel costs $54.

Check step by step: 4.54.5 h gives 450450 km, which uses 0.075(450)=33.750.075(450) = 33.75 L, which costs 1.60(33.75)=54.001.60(33.75) = 54.00, or $54.00. ✓

Working from the outside in. f(g(x))f(g(x)) means gg first, then ff, even though ff is written first. Start with the innermost brackets.

Multiplying instead of composing. f(g(x))f(g(x)) is not f(x)⋅g(x)f(x) \cdot g(x). For f(x)=x2+1f(x) = x^2 + 1 and g(x)=3x−2g(x) = 3x - 2, the product is 3x3−2x2+3x−23x^3 - 2x^2 + 3x - 2, but the composition is 9x2−12x+59x^2 - 12x + 5.

Forgetting brackets when substituting. f(x)=x2+1f(x) = x^2 + 1 with x=3x−2x = 3x - 2 gives (3x−2)2+1(3x - 2)^2 + 1, not 3x−22+13x - 2^2 + 1 or 3x2−2+13x^2 - 2 + 1.

Reading the domain from the simplified formula. In Example 3, g(f(x))g(f(x)) simplifies to 4−x4 - x, but x=−5x = -5 isn’t allowed, because f(−5)=−5f(-5) = \sqrt{-5} doesn’t exist. Check the inside function first.

Reusing the x-value on a graph. After you find g(1)=2g(1) = 2, the next input is 22, not 11. Move to x=2x = 2 on the graph of ff.

Assuming f(g(x)) = g(f(x)). It’s usually false. Example 1 and Example 2 both show different answers in the two orders.

1. (Warm-up) Use the tables to find f(g(1))f(g(1)), g(f(1))g(f(1)) and g(g(2))g(g(2)).

xx11223344
f(x)f(x)33114422
g(x)g(x)22441133
Solution

f(g(1))f(g(1)): g(1)=2g(1) = 2, then f(2)=1f(2) = 1. So f(g(1))=1f(g(1)) = 1.

g(f(1))g(f(1)): f(1)=3f(1) = 3, then g(3)=1g(3) = 1. So g(f(1))=1g(f(1)) = 1.

g(g(2))g(g(2)): g(2)=4g(2) = 4, then g(4)=3g(4) = 3. So g(g(2))=3g(g(2)) = 3.

2. (Warm-up) Let f(x)=2x+1f(x) = 2x + 1 and g(x)=x2g(x) = x^2. Find f(g(3))f(g(3)) and g(f(3))g(f(3)).

Solution

f(g(3))f(g(3)): g(3)=9g(3) = 9, then f(9)=19f(9) = 19.

g(f(3))g(f(3)): f(3)=7f(3) = 7, then g(7)=49g(7) = 49.

3. (Warm-up) Use the graphs of ff and gg in Key ideas to find g(f(0))g(f(0)), f(g(2))f(g(2)) and f(f(1))f(f(1)).

Solution

g(f(0))g(f(0)): the parabola gives f(0)=−2f(0) = -2, then the line gives g(−2)=5g(-2) = 5. So g(f(0))=5g(f(0)) = 5.

f(g(2))f(g(2)): the line gives g(2)=1g(2) = 1, then the parabola gives f(1)=−1f(1) = -1. So f(g(2))=−1f(g(2)) = -1.

f(f(1))f(f(1)): f(1)=−1f(1) = -1, then f(−1)=−1f(-1) = -1. So f(f(1))=−1f(f(1)) = -1.

4. (Core) Let f(x)=x2−3xf(x) = x^2 - 3x and g(x)=x+2g(x) = x + 2.

  • (a) Find f(g(x))f(g(x)) and g(f(x))g(f(x)).
  • (b) Solve f(g(x))=g(f(x))f(g(x)) = g(f(x)).
Solution

(a)

f(g(x))=(x+2)2−3(x+2)=x2+4x+4−3x−6=x2+x−2\begin{aligned} f\big(g(x)\big) &= (x + 2)^2 - 3(x + 2) \\ &= x^2 + 4x + 4 - 3x - 6 \\ &= x^2 + x - 2 \end{aligned}g(f(x))=(x2−3x)+2=x2−3x+2g\big(f(x)\big) = (x^2 - 3x) + 2 = x^2 - 3x + 2

(b)

x2+x−2=x2−3x+2⇒4x=4⇒x=1x^2 + x - 2 = x^2 - 3x + 2 \quad\Rightarrow\quad 4x = 4 \quad\Rightarrow\quad x = 1

Check: f(g(1))=f(3)=9−9=0f(g(1)) = f(3) = 9 - 9 = 0 and g(f(1))=g(−2)=0g(f(1)) = g(-2) = 0. ✓ So the two orders agree only at x=1x = 1.

5. (Core) Let f(x)=1x−1f(x) = \dfrac{1}{x - 1} and g(x)=x2g(x) = x^2. Find f(g(x))f(g(x)) and g(f(x))g(f(x)), and state the domain of each.

Solutionf(g(x))=1x2−1f\big(g(x)\big) = \frac{1}{x^2 - 1}

ff can’t accept 11, so we need x2≠1x^2 \ne 1: the domain is {x∈R∣x≠±1}\{x \in \mathbb{R} \mid x \ne \pm 1\}.

g(f(x))=(1x−1)2=1(x−1)2g\big(f(x)\big) = \left(\frac{1}{x - 1}\right)^2 = \frac{1}{(x - 1)^2}

f(x)f(x) needs x≠1x \ne 1, and gg accepts anything. The domain is {x∈R∣x≠1}\{x \in \mathbb{R} \mid x \ne 1\}.

6. (Core) Find functions ff and gg so that h(x)=f(g(x))h(x) = f(g(x)). (There’s more than one answer; give the most natural one.)

  • (a) h(x)=(5x−2)3h(x) = (5x - 2)^3
  • (b) h(x)=x2+9h(x) = \sqrt{x^2 + 9}
  • (c) h(x)=23x+1h(x) = 2^{3x + 1}
  • (d) h(x)=1(x+4)2h(x) = \dfrac{1}{(x + 4)^2}
Solution

Look for the “inside” expression and call it g(x)g(x).

(a) g(x)=5x−2g(x) = 5x - 2 and f(x)=x3f(x) = x^3.

(b) g(x)=x2+9g(x) = x^2 + 9 and f(x)=xf(x) = \sqrt{x}.

(c) g(x)=3x+1g(x) = 3x + 1 and f(x)=2xf(x) = 2^x.

(d) g(x)=x+4g(x) = x + 4 and f(x)=1x2f(x) = \dfrac{1}{x^2}. (Another answer: g(x)=(x+4)2g(x) = (x + 4)^2 and f(x)=1xf(x) = \dfrac{1}{x}.)

7. (Core) Oil leaking from a tanker spreads in a circle on the water. The radius after tt minutes is r(t)=4tr(t) = 4t metres, and the area of a circle is A(r)=πr2A(r) = \pi r^2.

  • (a) Find A(r(t))A(r(t)) and explain what it represents.
  • (b) Find the area after 55 minutes.
  • (c) When does the area reach 20002000 m²?
Solution

(a) A(r(t))=π(4t)2=16πt2A(r(t)) = \pi(4t)^2 = 16\pi t^2. It’s the area of the slick, in square metres, tt minutes after the leak starts.

(b) A(r(5))=16π(25)=400π≈1256.64A(r(5)) = 16\pi(25) = 400\pi \approx 1256.64 m².

(c) Solve 16πt2=200016\pi t^2 = 2000 with t>0t \gt 0:

t2=200016π≈39.79⇒t≈6.31t^2 = \frac{2000}{16\pi} \approx 39.79 \quad\Rightarrow\quad t \approx 6.31

The area reaches 20002000 m² after about 6.316.31 minutes.

8. (Challenge) Let f(x)=2x+3f(x) = 2x + 3. Find g(x)g(x) if f(g(x))=6x2−1f(g(x)) = 6x^2 - 1.

Solution

ff doubles its input and adds 33, so f(g(x))=2g(x)+3f(g(x)) = 2g(x) + 3. Set this equal to the given expression:

2g(x)+3=6x2−12g(x)=6x2−4g(x)=3x2−2\begin{aligned} 2g(x) + 3 &= 6x^2 - 1 \\ 2g(x) &= 6x^2 - 4 \\ g(x) &= 3x^2 - 2 \end{aligned}

Check: f(3x2−2)=2(3x2−2)+3=6x2−1f(3x^2 - 2) = 2(3x^2 - 2) + 3 = 6x^2 - 1. ✓

9. (Challenge) Let f(x)=1x−2f(x) = \dfrac{1}{x - 2}. Find f(f(x))f(f(x)) in simplest form and state its domain.

Solutionf(f(x))=11x−2−2f\big(f(x)\big) = \frac{1}{\dfrac{1}{x - 2} - 2}

Multiply the top and bottom by (x−2)(x - 2):

f(f(x))=x−21−2(x−2)=x−25−2xf\big(f(x)\big) = \frac{x - 2}{1 - 2(x - 2)} = \frac{x - 2}{5 - 2x}

Domain: the inside f(x)f(x) needs x≠2x \ne 2. The outside ff can’t accept 22, so we also need 1x−2≠2\dfrac{1}{x - 2} \ne 2, which means x−2≠12x - 2 \ne \tfrac{1}{2}, or x≠52x \ne \tfrac{5}{2}. (That matches the denominator 5−2x≠05 - 2x \ne 0.)

{x∈R  |  x≠2, x≠52}\left\{x \in \mathbb{R} \;\middle|\; x \ne 2,\ x \ne \tfrac{5}{2}\right\}

Notice that x=2x = 2 is excluded even though the simplified formula gives 01=0\tfrac{0}{1} = 0 there.