Unit 1, lesson 15

Function Composition

How to feed the output of one function into another, why the order matters, how to find the domain of a composite, and how to split a formula into an inner and an outer function.

  • Theory part 29
  • Practice part 30
  • Combining and Inverting Functions

A store takes 20 percent off everything, and you also hold a coupon for 10 dollars off. On a 50 dollar item, taking the percentage first leaves 30 dollars, while using the coupon first leaves 32 dollars. Each discount is a function, and the price you pay comes from running one after the other. Chaining functions like this is called composition, and as the two prices show, the order matters.

Key terms

Composition

Definition Let ff and gg be functions. The composition of ff with gg is the function f∘gf \circ g, read as ”ff composed with gg”, given by

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

Its domain is the set of all xx in the domain of gg for which g(x)g(x) lies in the domain of ff. The small circle is not multiplication, and (f∘g)(x)(f \circ g)(x) is in general different from the product f(x)⋅g(x)f(x) \cdot g(x).

In plain words Put xx into gg, then put the result into ff. Think of two machines linked so that the output of the first is the input of the second.

Example Let f(x)=x2+1f(x) = x^2 + 1 and g(x)=3x−2g(x) = 3x - 2. Replacing the input of ff by the whole expression 3x−23x - 2 gives

(f∘g)(x)=(3x−2)2+1=9x2−12x+5.\begin{aligned} (f \circ g)(x) &= (3x - 2)^2 + 1 \\[0.4em] &= 9x^2 - 12x + 5. \end{aligned}

At x=2x = 2 the inner step gives g(2)=4g(2) = 4 and the outer step gives f(4)=17f(4) = 17, and the formula agrees, since 36−24+5=1736 - 24 + 5 = 17. The product would give something else, f(2)⋅g(2)=5⋅4=20f(2) \cdot g(2) = 5 \cdot 4 = 20.

Inner and outer functions

Definition In the composition f∘gf \circ g, the function gg is the inner function and ff is the outer function. The inner function acts first, on xx itself. The outer function acts second, on the output g(x)g(x). In a formula, the inner function is the expression that fills the input slot of the outer one, and it helps to give the outer function its own letter for its input, as in f(u)f(u) with u=g(x)u = g(x).

In plain words The inner function is the first machine and the outer function is the second. In f(g(x))f(g(x)) the inner one is written inside the parentheses, even though it is the one you use first.

Example The function h(x)=1x−4h(x) = \frac{1}{x - 4} has inner function g(x)=x−4g(x) = x - 4 and outer function f(u)=1uf(u) = \frac{1}{u}. At x=6x = 6 the inner function gives u=2u = 2, and the outer function turns that into 12\frac{1}{2}. So h(6)=12h(6) = \frac{1}{2}, as direct substitution confirms.

Ordered evaluation

Definition To evaluate (f∘g)(a)(f \circ g)(a) at an input aa in the domain of gg, first compute b=g(a)b = g(a), check that bb is in the domain of ff, and then compute f(b)f(b). A composite of three functions is evaluated from the innermost function outward,

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

Composition is associative, (f∘g)∘h=f∘(g∘h)(f \circ g) \circ h = f \circ (g \circ h), so this triple composite needs no extra parentheses. The order of the letters, however, cannot be changed.

In plain words Work from the inside out, one step at a time, and write down each number along the way. The function written farthest to the right is the one you use first.

Example Let f(x)=2x+1f(x) = 2x + 1, g(x)=x2g(x) = x^2 and h(x)=x−3h(x) = x - 3. Then

(f∘g∘h)(5)=f(g(h(5)))=f(g(2))=f(4)=9.\begin{aligned} (f \circ g \circ h)(5) &= f(g(h(5))) \\[0.4em] &= f(g(2)) \\[0.4em] &= f(4) \\[0.4em] &= 9. \end{aligned}

Starting from the outside instead and computing f(5)=11f(5) = 11 first gives a wrong answer.

Noncommutativity

Definition Composition is not commutative. For most pairs of functions, f∘gf \circ g and g∘fg \circ f are different functions, either because they differ at some input or because they have different domains. Some pairs do agree in both orders, for example f(x)=2xf(x) = 2x and g(x)=3xg(x) = 3x, which give 6x6x either way, but equality must never be assumed.

In plain words Doing gg and then ff is usually not the same as doing ff and then gg, just as socks and then shoes is not the same as shoes and then socks.

Example Let f(x)=x2f(x) = x^2 and g(x)=x+3g(x) = x + 3. Then

(f∘g)(x)=(x+3)2=x2+6x+9,(g∘f)(x)=x2+3.\begin{aligned} (f \circ g)(x) &= (x + 3)^2 \\[0.4em] &= x^2 + 6x + 9, \\[0.4em] (g \circ f)(x) &= x^2 + 3. \end{aligned}

At x=1x = 1 the first gives 1616 and the second gives 44. The discounts from the opening behave the same way. With s(p)=0.8ps(p) = 0.8p for the sale and c(p)=p−10c(p) = p - 10 for the coupon, a price of pp dollars becomes

(c∘s)(p)=0.8p−10or(s∘c)(p)=0.8(p−10)=0.8p−8,\begin{aligned} (c \circ s)(p) &= 0.8p - 10 \quad \text{or} \\[0.4em] (s \circ c)(p) &= 0.8(p - 10) \\[0.4em] &= 0.8p - 8, \end{aligned}

so using the coupon first always costs 2 dollars more.

Composite domain

Definition The domain of f∘gf \circ g is

Df∘g={ x∈Dg∣g(x)∈Df }.D_{f \circ g} = \{\, x \in D_g \mid g(x) \in D_f \,\}.

An input must pass two checks. It must be accepted by gg, and its output g(x)g(x) must be accepted by ff. The domain comes from these two conditions on the original functions, not from the simplified formula of the composite.

In plain words Check the first machine, then check that what it hands over fits the second machine. An input that fails either check is out.

Example Let f(x)=1x−2f(x) = \frac{1}{x - 2} and g(x)=xg(x) = \sqrt{x}. The inner function needs x≥0x \ge 0. The outer function needs g(x)≠2g(x) \ne 2, that is x≠2\sqrt{x} \ne 2, so x≠4x \ne 4. Therefore

(f∘g)(x)=1x−2,x∈[0,4)∪(4,∞).\begin{gathered} (f \circ g)(x) = \frac{1}{\sqrt{x} - 2}, \\[0.8em] x \in [0, 4) \cup (4, \infty). \end{gathered}

Simplifying can hide a condition. With F(x)=x2F(x) = x^2 and G(x)=xG(x) = \sqrt{x} the composite (F∘G)(x)=(x)2(F \circ G)(x) = (\sqrt{x})^2 simplifies to xx, yet its domain is only [0,∞)[0, \infty), because G(−1)G(-1) is not a real number.

Decomposing a function

Definition To decompose a function hh means to find functions ff and gg with h=f∘gh = f \circ g, that is, f∘gf \circ g has the same domain as hh and f(g(x))=h(x)f(g(x)) = h(x) for every xx in it. A decomposition is never unique. The trivial choices g(x)=xg(x) = x or f(u)=uf(u) = u always work and say nothing, so a useful decomposition takes as the inner function a part of the formula that is computed first, such as the expression under a root, inside a power or in a denominator.

In plain words Ask what you would compute first on a calculator. That first part is the inner function, and whatever you then do to its result is the outer function.

Example The function h(x)=(x2+1)5h(x) = (x^2 + 1)^5 is f∘gf \circ g with inner function g(x)=x2+1g(x) = x^2 + 1 and outer function f(u)=u5f(u) = u^5. Another valid choice is g(x)=x2g(x) = x^2 with f(u)=(u+1)5f(u) = (u + 1)^5. Both give h(1)=25=32h(1) = 2^5 = 32, as they must. The first split, with a plain power outside, is the one that the chain rule works with most easily.

Check yourself

  1. Let f(x)=2x−5f(x) = 2x - 5 and g(x)=x2+1g(x) = x^2 + 1. Find (f∘g)(3)(f \circ g)(3) and (g∘f)(3)(g \circ f)(3).
Show the answer

Work from the inside out. For the first, g(3)=10g(3) = 10 and f(10)=15f(10) = 15, so (f∘g)(3)=15(f \circ g)(3) = 15. For the second, f(3)=1f(3) = 1 and g(1)=2g(1) = 2, so (g∘f)(3)=2(g \circ f)(3) = 2.

  1. Let f(x)=x−1f(x) = \sqrt{x - 1} and g(x)=1xg(x) = \frac{1}{x}. Find the domain of f∘gf \circ g.
Show the answer

The inner function needs x≠0x \ne 0. The outer function needs 1x−1≥0\frac{1}{x} - 1 \ge 0, that is

1−xx≥0,\frac{1 - x}{x} \ge 0,

which holds exactly for 0<x≤10 < x \le 1. The domain is (0,1](0, 1]. For example x=2x = 2 fails, since 12−1<0\frac{1}{2} - 1 < 0.

  1. Find an inner function gg and an outer function ff with f∘g=hf \circ g = h for the following function.
h(x)=3(x2+4)2h(x) = \frac{3}{(x^2 + 4)^2}
Show the answer

One choice is g(x)=x2+4g(x) = x^2 + 4 and f(u)=3u2f(u) = \frac{3}{u^2}. Since g(x)≥4g(x) \ge 4, the outer function never meets u=0u = 0, so both hh and f∘gf \circ g have domain R\mathbb{R}. As a check, g(0)=4g(0) = 4 and f(4)=316=h(0)f(4) = \frac{3}{16} = h(0). Other splits, such as g(x)=x2g(x) = x^2 and f(u)=3(u+4)2f(u) = \frac{3}{(u + 4)^2}, are also correct.

How this lesson connects

Where this leads in Calculus