If f and g are functions, the composite function f∘g maps a set of input values to a set of output values such that the output values of g are used as input values of f. It can be written two ways:
Read f(g(x)) from the inside out: do g first, then f. Because f only accepts certain inputs, the domain of f∘g is restricted to those inputs of g whose output is in the domain of f.
Example. Let f(x) = √x and g(x) = x − 4. Then (f∘g)(13) = f(9) = 3. But (f∘g)(2) = f(−2), and √(−2) is not a real number, so (f∘g)(2) is undefined. Only x ≥ 4 works, because g(x) = x − 4 must be at least 0.
In (f∘g)(x) = f(g(x)), the output of g becomes the input of f. Pick a pair of functions and an input and follow the chain. Some inputs make the composition undefined.
Values of f∘g can be calculated or estimated from graphical, numerical, analytical, or verbal representations of f and g. The method never changes: use the output from g as the input for f.
| Representation | How to find (f∘g)(a) |
|---|---|
| table | find g(a) in g's table, then look that number up as an input in f's table |
| graph | read g(a) from g's graph, then use it as an x-value on f's graph |
| formula | compute g(a), then substitute the result into f |
| words | translate each sentence into a function, then chain the steps |
Example (words). A car goes g(t) = 45t miles in t hours and uses f(m) = m/30 gallons for m miles. Then (f∘g)(4) = f(180) = 6 gallons: the output of g (miles) is the input of f (miles).
With tables, use an output of the inner function as an input of the outer function. If that value is not in the outer function's table, the composition is undefined there.
| x | 0 | 1 | 2 | 3 | 4 |
|---|---|---|---|---|---|
| f(x) | 4 | 1 | 6 | 3 | 0 |
| x | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| g(x) | 3 | 0 | 4 | 2 | 7 |
| x | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| g(x) | 3 | 0 | 4 | 2 | 7 |
| f(g(x)) | 3 | 4 | 0 | 6 | undefined |
Composition is not commutative. The functions f∘g and g∘f are typically different, so f(g(x)) and g(f(x)) are typically different values.
Example. Let f(x) = 2x + 3 and g(x) = x². Then (f∘g)(2) = f(4) = 11, but (g∘f)(2) = g(7) = 49. As formulas, f(g(x)) = 2x² + 3 and g(f(x)) = (2x + 3)² = 4x² + 12x + 9.
Compare f∘g with g∘f for the same pair. Blue is f(g(x)) and gold is g(f(x)). Composition is not commutative, so the two are typically different functions.
The function I(x) = x is the identity function. Composing it with any function g changes nothing:
The identity does for composition what 0 does for addition (a + 0 = a) and what 1 does for multiplication (a · 1 = a). This idea comes back in the next topic: a function and its inverse compose to give the identity.
The identity function I(x) = x returns its input. Composing any function with it changes nothing. Compare it with h(x) = x + 1, which is not the identity.
Function composition is useful for relating two quantities that are not directly related by an existing formula. If the radius of a circle depends on time and the area depends on radius, composition connects area and time.
When analytic forms of f and g are available, an analytic form of f∘g is built by substituting g(x) for every x in f.
To build f(g(x)) analytically, substitute g(x) for every x in f. Then check: the number from the chain of two steps should match the number from the new formula.
A numerical or graphical representation of f∘g can often be built by calculating or estimating values for (x, f(g(x))). A table with a column for x, a column for g(x), and a column for f(g(x)) keeps the order clear. The graph of f∘g has gaps wherever the composition is undefined.
Example.For f(x) = √x and g(x) = x − 4, the values at x = 4, 5, 6 are f(g(4)) = √0 = 0, f(g(5)) = √1 = 1, and f(g(6)) = √2 ≈ 1.414. For x < 4 the table says undefined.
A numerical or graphical representation of f∘g comes from calculating (x, g(x), f(g(x))) for many inputs. Orange dots are the table values and the curve shows the whole function.
| x | -2 | -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|---|---|---|
| g(x) | -6 | -5 | -4 | -3 | -2 | -1 | 0 | 1 | 2 |
| f(g(x)) | undefined | undefined | undefined | undefined | undefined | undefined | 0 | 1 | 1.414 |
A function given analytically can often be decomposed into less complicated functions. Ask what is done to x first, then what is done to that result. When properly decomposed, the variable in the outer function replaces each instance of the inner function.
Example. h(x) = (3x − 4)⁵. First compute 3x − 4 (inner g), then raise to the fifth power (outer f(u) = u⁵). So h = f∘g. A function can have more than two layers: 5·3x−2 + 1 is three steps (subtract 2, raise 3 to it, then multiply by 5 and add 1).
A function given analytically can be decomposed into simpler functions. Work from the inside out: whatever you do to x first is the inner function. In the outer function, the variable replaces each instance of the inner function.
The transformations from earlier units are compositions in disguise. An additive transformation that translates a graph is the composition of g(x) = x + k with f. A multiplicative transformation that dilates a graph is the composition of g(x) = kx with f.
| Composition | Effect on the graph of f |
|---|---|
| f(g(x)) = f(x + k) | horizontal translation (left if k > 0) |
| g(f(x)) = f(x) + k | vertical translation (up if k > 0) |
| f(g(x)) = f(kx) | horizontal dilation by a factor of 1/k |
| g(f(x)) = k·f(x) | vertical dilation by a factor of k |
An additive transformation is a composition with g(x) = x + k, and a multiplicative transformation is a composition with g(x) = kx. Whether g goes inside or outside decides whether the change is horizontal or vertical. Blue is the new graph and gold is the original f.