Composing functions algebraically
Two functions run one after the other. Is there a single rule that goes straight from the first input to the final output?
Where you are 5 in Combining and composing functions
When you reach for it
In evaluating a composition at a number, a number went through the inner function and the answer went into the outer one. That works one input at a time. If you want the value at many inputs, or want to study the chained function as a function in its own right (its graph, its smallest value, where it equals something), you want one formula that does both steps at once. Composing algebraically finds that formula: the whole inner rule is substituted for the input of the outer rule, and the result is simplified.
Reach for it when a question asks for f(g(x)) or (f \circ g)(x) as an expression, when a situation happens in two stages and you want one rule from the start to the end (time gives a radius, the radius gives an area), and in reverse, when a complicated formula is easier to handle once you see it as a simple function with another simple function inside it.
This lesson runs over two days. Day 1 is the move itself: substituting one rule into another, simplifying, checking with a number, and seeing that the two orders give different functions. Day 2 uses the move in situations with units, and runs it backwards, breaking a function into a composition.
The procedure
Day 1: substituting the whole inner rule
Let f(x) = x^2 - 6x and g(x) = 2x + 3. By definition,
so the task is to evaluate f at an expression. The rule for f says: take whatever the input is, square it, and subtract six times it. The letter x in f(x) = x^2 - 6x only marks where the input goes. Here the input is the whole expression 2x + 3, so every x in the rule for f is replaced by (2x + 3), in brackets, because the whole input is squared and the whole input is multiplied by 6:
The square was expanded as (2x + 3)(2x + 3), and -6 was distributed over both terms of the bracket. The 12x and -12x canceled, which nobody could have predicted from the two separate rules: composing can produce a much simpler formula, or a much more complicated one.
For the other order, g is outside, so its rule “double the input and add 3” is applied to the input x^2 - 6x:
Check with a number. Each formula can be tested by evaluating the composition at one number the slow way, inside first. At x = 1: g(1) = 5 and f(5) = 25 - 30 = -5, while the formula gives 4(1)^2 - 9 = -5. The other order: f(1) = -5 and g(-5) = -7, while 2 - 12 + 3 = -7. Agreement at one number does not prove a formula right, but a slip in expanding almost always shows up, so the check costs little and catches a lot.
Day 1: the order is part of the question
The two formulas, 4x^2 - 9 and 2x^2 - 12x + 3, are different functions, and their graphs show it: one parabola has its lowest point at (0, -9), the other at (3, -15).
They give the same output only where 4x^2 - 9 = 2x^2 - 12x + 3, that is x^2 + 6x - 6 = 0, at \displaystyle x = -3 \pm \sqrt{15}. At every other input the two orders disagree. So f \circ g and g \circ f are in general different, and writing them in the wrong order is a different question, not a different way of writing the same answer. Some pairs do commute (Example 5 builds one), but that is a fact about those two functions, to be checked rather than assumed.
The circle is still not multiplication. The product of these two functions is f(x)\,g(x) = (x^2 - 6x)(2x + 3), which expands to 2x^3 - 9x^2 - 18x, a cubic, and nothing like either composition.
Day 2: compositions that describe a situation
In a situation, each function turns one kind of quantity into another, and composing them is only meaningful when the output of the inner function is the kind of quantity the outer function takes in: minutes into a function of time, a radius in centimeters into a function of a radius in centimeters. The composite formula then goes straight from the first quantity to the last, and its input and output carry those units. Examples 6 and 7 build two such formulas and use them in both directions.
Day 2: breaking a function into a composition
Running the move backwards is called decomposing. Given h(x) = (3x - 1)^5, ask what is computed first when you evaluate it at a number. You would work out 3x - 1, and only then raise it to the fifth power. That first calculation is the inner function and the last one is the outer function:
A decomposition is never unique. The same h is also f(g(x)) with g(x) = 3x and f(x) = (x - 1)^5, and every function is the composition of itself with x \mapsto x, which says nothing. The useful decomposition is the one that splits the work into pieces you already understand, which is usually “the expression in the brackets, then what is done to the brackets”.
Worked examples
Day 1: two lines, and a line composed with itself
Let a(x) = 4 - 3x and b(x) = \dfrac{x}{2} + 5. Find (a) a(b(x)), (b) b(a(x)) and (c) (a \circ a)(x).
Solution(a) b is inside, so every x in the rule for a becomes \displaystyle \left(\frac{x}{2} + 5\right). Then distribute the -3 over both terms:
(b) Now a is inside, and the rule for b halves its input and adds 5:
(c) (a \circ a)(x) = a(a(x)) = 4 - 3(4 - 3x), which is 4 - 12 + 9x = 9x - 8.
Check (c) at x = 2: a(2) = -2 and a(-2) = 10, while 9(2) - 8 = 10.
Both orders in (a) and (b) have slope \displaystyle -\frac{3}{2}, which is the product of the slopes -3 and \displaystyle \frac{1}{2}, and in (c) the slope is (-3)(-3) = 9. Exercise 25 asks why that always happens for two linear functions. The two orders still differ, because their constant terms do.
Day 1: a square to expand
Let m(x) = 2x^2 - x + 1 and n(x) = x - 3. Find m(n(x)) and n(m(x)), and check the first at x = 3.
SolutionIn m(n(x)) the input of m is x - 3, and it appears twice in the rule for m, so it is substituted twice:
The minus sign in front of (x - 3) applies to both terms, which is why +3 appears. The other order only subtracts 3 from the whole output: n(m(x)) = 2x^2 - x + 1 - 3 = 2x^2 - x - 2.
Check at x = 3: n(3) = 0 and m(0) = 1, while 2(9) - 13(3) + 22, which is 18 - 39 + 22 = 1.
The two results also have a picture. Putting x - 3 inside a function moves its graph 3 to the right, and subtracting 3 outside moves it 3 down, which is how transformations of a graph are compositions with very simple functions.
Day 1: a square root that does not split
Let \displaystyle c(x) = \sqrt{x} and d(x) = x^2 + 9. Find c(d(x)) and d(c(x)), and say for which inputs each formula is valid.
Solution\displaystyle c(d(x)) = \sqrt{x^2 + 9}, and that is as simple as it gets. It is tempting to write x + 3, but a square root does not split over a sum: at x = 4, \displaystyle \sqrt{16 + 9} = 5, while 4 + 3 = 7. Since x^2 + 9 is at least 9 for every real x, the square root always exists, and the formula is valid for every real number.
\displaystyle d(c(x)) = \left(\sqrt{x}\right)^2 + 9 = x + 9, but only for x \ge 0. The simplified formula x + 9 happily accepts x = -1, giving 8, yet the composition does not: \displaystyle c(-1) = \sqrt{-1} is not a real number, so the chain never starts. Simplifying can erase the record of which inputs were allowed, so the condition x \ge 0 has to be carried along by hand. Collecting those conditions is the subject of the domain of a composition.
Day 1: fractions inside fractions
Let t(x) = \dfrac{2}{x + 5} and v(x) = \dfrac{1}{x}. Find t(v(x)) and v(t(x)) as single fractions.
SolutionSubstituting v(x) for the input of t gives a fraction inside a fraction. Multiplying its top and bottom by x, which is allowed because x \ne 0 (otherwise v(x) would not exist), clears the inner fraction:
valid for x \ne 0, and also \displaystyle x \ne -\frac{1}{5}, where v(x) = -5 and t would divide by zero.
For the other order, dividing 1 by a fraction turns it upside down:
valid for x \ne -5, since t(-5) does not exist, even though \displaystyle \frac{-5 + 5}{2} = 0 looks harmless.
Check at x = 1: v(1) = 1 and \displaystyle t(1) = \frac{2}{6} = \frac{1}{3}, while \displaystyle \frac{2(1)}{1 + 5} = \frac{1}{3}. And \displaystyle t(1) = \frac{1}{3}, \displaystyle v\!\left(\frac{1}{3}\right) = 3, while \displaystyle \frac{1 + 5}{2} = 3.
Day 1: choosing a number so that the order does not matter
Let f(x) = 3x + k and g(x) = 2x - 1, where k is a constant. Find the value of k for which f \circ g and g \circ f are the same function.
SolutionCompose both ways with k left as a letter:
The x terms already agree. Two linear expressions are equal for every x exactly when their constant terms also agree, so -3 + k = 2k - 1, which gives k = -2.
Check: with f(x) = 3x - 2, f(g(x)) = 6x - 3 - 2 = 6x - 5 and g(f(x)) = 6x - 4 - 1 = 6x - 5. For every other value of k the two orders differ by the constant k + 2, at every input.
Day 2: a spreading puddle
Water spills on a floor and spreads in a circle. After t minutes its radius is r(t) = 4t + 10 centimeters, and a circle of radius r centimeters has area A(r) = \pi r^2 square centimeters.
(a) Find (A \circ r)(t) and say what it gives. (b) Find the area after 5 minutes. (c) After how many minutes is the area 3600\pi square centimeters?
Solution(a) r turns a time into a radius, and A takes a radius, so r is inside:
It gives the area of the puddle, in square centimeters, t minutes after the spill. The other order, r(A(\cdot)), would feed an area into a function that expects minutes, and means nothing.
(b) (A \circ r)(5) = \pi(400 + 400 + 100) = 900\pi \approx 2827 square centimeters. The slow way agrees: r(5) = 30 and A(30) = 900\pi.
(c) The output is known, so solve \pi(4t + 10)^2 = 3600\pi. Dividing by \pi gives (4t + 10)^2 = 3600, so 4t + 10 = 60; the value -60 is rejected because a radius is positive. Then 4t = 50 and t = 12.5 minutes.
Day 2: two currency exchanges
Suppose one dollar buys 0.9 euros and one euro buys 160 yen, so E(d) = 0.9d gives the euros for d dollars and Y(e) = 160e gives the yen for e euros. Find a single formula for the yen bought with d dollars by changing to euros first, and find how many dollars buy 36\,000 yen.
SolutionDollars go into E and come out as euros, which is what Y takes, so E is inside:
Each dollar ends up as 144 yen, and 144 = 160 \times 0.9: composing two exchanges multiplies the rates, the same way chained conversion factors multiply. For 36\,000 yen, 144d = 36\,000 gives d = 250 dollars. Check: E(250) = 225 euros, and Y(225) = 36\,000 yen.
E(Y(d)) is a calculation, 0.9(160d), but it treats a number of yen as a number of dollars, so it describes no real exchange.
Day 2: breaking functions into compositions
Write each function as f(g(x)) with neither piece equal to x itself. (a) \displaystyle k(x) = \sqrt{7 - 3x} (b) p(x) = (x^2 - 2)^3 - 4(x^2 - 2) (c) q(x) = \dfrac{1}{(x + 4)^2}, in two different ways.
Solution(a) Evaluating k at a number, you first work out 7 - 3x and then take its square root. So g(x) = 7 - 3x and \displaystyle f(x) = \sqrt{x}. Check: \displaystyle f(g(x)) = \sqrt{7 - 3x}.
(b) The same bracket, x^2 - 2, appears twice. Call it the inner function, g(x) = x^2 - 2. What is done to it is “cube it and subtract four times it”, so f(x) = x^3 - 4x. Check: f(g(x)) = (x^2 - 2)^3 - 4(x^2 - 2). Expanding p would give a degree-six polynomial; the decomposition shows it is built from a quadratic and a cubic.
(c) First x + 4 is worked out, then squared, then turned upside down. The cut can go after either stage. With g(x) = x + 4 the rest is \displaystyle f(x) = \frac{1}{x^2}. With g(x) = (x + 4)^2 the rest is \displaystyle f(x) = \frac{1}{x}. Both are correct; which is more useful depends on what you want to do next.
Day 2: recovering the outer function
Find f so that f(g(x)) = 4x^2 - 9 when g(x) = 2x + 3.
SolutionWrite u for the inner output, u = 2x + 3. Then \displaystyle x = \frac{u - 3}{2}, and substituting this into 4x^2 - 9 writes the output in terms of u alone:
So whatever f receives, it squares it and subtracts six times it: f(x) = x^2 - 6x. This is the pair from the procedure, recovered from the composition and one of its pieces. Check: f(2x + 3) = 4x^2 - 9 was worked out on Day 1.
The step \displaystyle x = \frac{u - 3}{2} undoes g, which a linear g with nonzero slope always allows. Undoing a function is exactly what finding an inverse studies.
Boundaries
Every input slot gets the whole inner expression. Each occurrence of x in the outer rule is replaced by the inner expression in brackets, as many times as x appears. Without the brackets, f(2x + 3) for f(x) = x^2 - 6x would square only part of the input.
A simplified formula can hide inputs that are not allowed. \displaystyle (\sqrt{x})^2 + 9 simplifies to x + 9, but only for x \ge 0 (Example 3), and \displaystyle \frac{1}{2/(x + 5)} simplifies to \displaystyle \frac{x + 5}{2}, but not at x = -5 (Example 4). An input belongs to the composition only if both steps work, and that has to be decided before simplifying, not read off the final formula.
Order matters. f \circ g and g \circ f are different functions in general. Equality is possible for special pairs and is shown by composing both ways, never assumed.
The circle is not a product. f(g(x)) substitutes; f(x)\,g(x) multiplies outputs.
Algebra does not distribute every rule. \displaystyle \sqrt{x^2 + 9} is not x + 3, and (x + 4)^2 is not x^2 + 16. Substituting and then simplifying only uses steps that are true for every allowed input. In particular \displaystyle \sqrt{x^2} = \lvert x \rvert, not x (Exercise 8).
In context, units must chain. The inner function’s output must be the quantity the outer function takes in. Otherwise the formula can be computed but means nothing.
Decomposition is not unique. A function usually splits in several ways, and splitting off x \mapsto x is always possible and always useless.
Where this goes next
The question left open by Examples 3 and 4, exactly which inputs survive both steps, is the domain of a composition. Composition is also the language of undoing: two functions are inverses when f(g(x)) = x and g(f(x)) = x for every allowed input, and Example 9 already undid a linear function to recover a piece. Proving two functions are inverses is done by exactly the substitution of this lesson.
Order mattering is not special to functions of numbers. Multiplying matrices is composing the transformations they stand for, which is why matrix multiplication depends on order too. In calculus, decomposition does real work: the rate of change of f(g(x)) is found by the chain rule, which needs the inner and outer functions named, and u-substitution runs the same split backwards, naming the inner function u as Example 9 did.
Exercises
Day 1: composing formulas
Let A(x) = 2x - 5 and B(x) = x^2 + 1.
- Find A(B(x)).
- Find B(A(x)).
- Find (A \circ A)(x).
- Find (B \circ B)(x).
- Find (B \circ A)(3) twice: from your formula in Exercise 2, and inside first.
Let H(x) = x^2 + 4x and J(x) = x - 2.
- Find H(J(x)).
- Find J(H(x)).
Day 1: roots and fractions
Let \displaystyle R(x) = \sqrt{x - 3} and S(x) = x^2 + 3.
- Find R(S(x)) and simplify it as far as is true for every real x.
- Find S(R(x)), and say for which x your simplified formula is valid.
Let M(x) = \dfrac{4}{x} and N(x) = x - 2.
- Find M(N(x)).
- Find N(M(x)) as a single fraction.
- Find (M \circ M)(x), and say for which x it is valid.
Day 1: the order of composing
- Let f(x) = 3x + 2 and g(x) = 5x + c. Find c so that f(g(x)) = g(f(x)) for every x.
- Let p(x) = x^2 and q(x) = x + 4. Find every x with p(q(x)) = q(p(x)).
Day 2: in context
- A spherical balloon is blown up so that its radius after t seconds is r(t) = 3t centimeters. A sphere of radius r has volume \displaystyle V(r) = \frac{4}{3}\pi r^3. Find V(r(t)), and the volume after 2 seconds.
- A temperature in degrees Fahrenheit, F, is \displaystyle C(F) = \frac{5}{9}(F - 32) degrees Celsius, and a temperature of C degrees Celsius is K(C) = C + 273.15 kelvins. Which function is inside in a formula that turns Fahrenheit into kelvins? Write the formula, and use it at F = 212.
- A workshop makes n(t) = 40t items in t hours, and making n items costs C(n) = 500 + 12n dollars. Find C(n(t)), and the number of hours for which the cost is 4340 dollars.
Day 2: breaking functions apart
Write each function as f(g(x)), with neither f nor g equal to x itself.
- h(x) = (5x + 2)^3
- \displaystyle h(x) = \sqrt{x^2 - 7}
- h(x) = \dfrac{1}{2x - 9}
- h(x) = (x^2 + 3)^2 + 5(x^2 + 3)
- Given g(x) = x + 1, find f with f(g(x)) = x^2 + 2x.
- Given f(x) = x^2, find every linear function g with f(g(x)) = 9x^2 - 12x + 4.
Reasoning
- Someone claims that for f(x) = x^2 - 6x and g(x) = 2x + 3, f(g(x)) is the same as f(x)\,g(x). Test the claim at x = 0 and explain what each expression does.
- Show that composing two linear functions, f(x) = mx + b and g(x) = nx + c, always gives a linear function, and that the slope of f \circ g is mn.
- Explain why every function h can be written as f(g(x)) in at least two ways, and why that alone does not make decomposition useful.
- In Example 3, d(c(x)) simplified to x + 9. Explain why the composition is still not the same function as x + 9.
Answers
- A(B(x)) = 2x^2 - 3. 2(x^2 + 1) - 5 = 2x^2 + 2 - 5.
- B(A(x)) = 4x^2 - 20x + 26. (2x - 5)^2 + 1 expands to 4x^2 - 20x + 25 + 1.
- (A \circ A)(x) = 4x - 15. 2(2x - 5) - 5 = 4x - 10 - 5.
- (B \circ B)(x) = x^4 + 2x^2 + 2. (x^2 + 1)^2 + 1 expands to x^4 + 2x^2 + 1 + 1.
- Both ways give 2. Formula: 4(9) - 20(3) + 26 = 2. Inside first: A(3) = 1 and B(1) = 2.
- H(J(x)) = x^2 - 4. (x - 2)^2 + 4(x - 2) expands to x^2 - 4x + 4 + 4x - 8.
- J(H(x)) = x^2 + 4x - 2. The outer rule only subtracts 2 from the output.
- R(S(x)) = \lvert x \rvert. \displaystyle \sqrt{(x^2 + 3) - 3} = \sqrt{x^2}, and the square root of a square is the distance from zero, so \displaystyle \sqrt{x^2} = \lvert x \rvert (at x = -2 it is 2, not -2).
- S(R(x)) = x, valid for x \ge 3. \displaystyle \left(\sqrt{x - 3}\right)^2 + 3 = x - 3 + 3, but R(x) is real only when x - 3 \ge 0.
- \displaystyle M(N(x)) = \frac{4}{x - 2}, valid for x \ne 2.
- \displaystyle N(M(x)) = \frac{4 - 2x}{x}, valid for x \ne 0. \displaystyle \frac{4}{x} - 2 = \frac{4}{x} - \frac{2x}{x}.
- (M \circ M)(x) = x, valid for x \ne 0. \displaystyle \frac{4}{4/x} = 4 \cdot \frac{x}{4} = x, but M(0) does not exist.
- c = 4. f(g(x)) = 15x + 3c + 2 and g(f(x)) = 15x + 10 + c; equal constant terms need 3c + 2 = 10 + c.
- \displaystyle x = -\frac{3}{2} only. (x + 4)^2 = x^2 + 4 gives 8x + 16 = 4. Check: \displaystyle q(-\frac{3}{2}) = \frac{5}{2} and \displaystyle p(\frac{5}{2}) = \frac{25}{4}; \displaystyle p(-\frac{3}{2}) = \frac{9}{4} and \displaystyle q(\frac{9}{4}) = \frac{25}{4}.
- V(r(t)) = 36\pi t^3, and after 2 seconds the volume is 288\pi \approx 904.8 cubic centimeters. \displaystyle \frac{4}{3}\pi(3t)^3 = \frac{4}{3}\pi \cdot 27t^3, and 36\pi \cdot 8 = 288\pi.
- C is inside, since K takes degrees Celsius: \displaystyle K(C(F)) = \frac{5}{9}(F - 32) + 273.15. At F = 212: \displaystyle \frac{5}{9}(180) + 273.15 = 100 + 273.15 = 373.15 kelvins.
- C(n(t)) = 500 + 480t, and the cost is 4340 dollars after 8 hours. 12(40t) = 480t, and 500 + 480t = 4340 gives 480t = 3840.
- g(x) = 5x + 2 and f(x) = x^3.
- g(x) = x^2 - 7 and \displaystyle f(x) = \sqrt{x}.
- g(x) = 2x - 9 and \displaystyle f(x) = \frac{1}{x}.
- g(x) = x^2 + 3 and f(x) = x^2 + 5x. The bracket appears twice; f squares its input and adds five times it.
- f(x) = x^2 - 1. Write u = x + 1, so x = u - 1 and x^2 + 2x = (u - 1)^2 + 2(u - 1), which is u^2 - 1. Check: (x + 1)^2 - 1 = x^2 + 2x.
- g(x) = 3x - 2 or g(x) = 2 - 3x. 9x^2 - 12x + 4 = (3x - 2)^2, and (2 - 3x)^2 is the same square, so both work.
- The claim is false. f(g(0)) = f(3) = 9 - 18 = -9, while f(0)\,g(0) = 0 \cdot 3 = 0. f(g(x)) feeds the output of g into f and equals 4x^2 - 9; f(x)\,g(x) multiplies the two outputs at the same input and equals 2x^3 - 9x^2 - 18x.
- f(g(x)) = m(nx + c) + b, which is mnx + (mc + b) by the distributive property. That is again of the form (number)\cdot x + (number), so it is linear, with slope mn and intercept mc + b.
- h(x) = f(g(x)) with f(x) = x and g = h, and also with f = h and g(x) = x, because composing with x \mapsto x changes nothing. Neither split breaks h into simpler pieces, so they are always available and never help; a useful decomposition makes both pieces simpler than h.
- Two functions are the same only if they have the same inputs and the same output at each. The composition d(c(x)) needs \displaystyle c(x) = \sqrt{x} first, which is not real for x < 0, so negative inputs are not allowed; x + 9 accepts them. They agree on x \ge 0 and differ in their inputs.