Composition of Functions
Learning goals
- Read right to left, with acting first
- Use associativity to drop parentheses from a chain
- Check the domain against the range of the inner function
- Show that composition need not commute, but sometimes does
- Decompose a function, knowing the split is a choice
- Write for , never for the square
Reading a composition right to left
Give the operation its symbol. The composition of and , written , is the function
You feed to , and then feed the result to . The circle is the operation sign, exactly as is the sign for addition, and names a new function built from the two you started with.
The one thing to fix in your reading, because it causes more confusion than anything else in this lesson, is the order. In the function on the right, , acts first, and the function on the left, , acts second. The notation runs right to left, opposite to the way you read a sentence. The reason is built into the definition: has in the inner parentheses, and the inner operation always happens before the outer one. So means “do , then ,” never “do , then .”
Worked example 1 Both orders of the same two functions
Let and . Compute and , keeping track of which function acts first.
For , the inner function is , so substitute into :
For , the inner function is now , so substitute into :
The two results, and , are different functions; they agree only where , that is at . Swapping the order changed the answer, which is the first sign that composition, unlike addition, does not always let you reverse the two inputs.
Check your understanding
For and , which expression is ?
In the right function acts first, then acts on the result.
The trap is the other order, .
The associative law
Addition of three numbers needs no parentheses: and are equal, so we simply write . Composition has the same property, and it is a genuine theorem worth proving, because it is what makes a chain of three or more functions unambiguous.
Composition is associative#
Let , , and be functions, and consider the two ways to group their composition, and . Two functions are equal exactly when they have the same domain and agree at every input, the equality test from Function Notation, so we check the values and the domains.
For the values, apply each grouping to an input and unfold the definition one step at a time. The left grouping gives
and the right grouping gives
Both collapse to the single expression , so the two functions agree wherever they are defined.
For the domains, read off what each grouping requires. Building is legal exactly when so that exists, then so that exists, then so that the outer applies. These three conditions are the same for both groupings, so the two functions have the same domain as well as the same values. By the equality test they are the same function.
Because the grouping never matters, we drop the parentheses and write . The same holds for any number of functions, which is why an iterated composition like is unambiguous and needs no bracketing to say what it means.
The identity function
Addition has the number : adding it changes nothing, since . Composition has a function that plays the same role, the identity function
which hands back its input untouched. Composing with it changes nothing, but stating that carefully means being honest about the domain, because the equality test demands more than a matching formula.
The identity function is neutral for composition#
Let be a function, and let . We show and , taking on the correct set each time.
Take with the same domain as . Then for every ,
and the domain of is , which is all of because already lies there. Same domain, same values, so .
Now take on a set that contains the outputs of , such as its codomain. Then for every ,
and the domain is , which is again all of because every output of is in that set. So .
The care is the whole point. Sharing the formula is not enough for two functions to be equal; the equality test also demands the same domain. That is why must be taken on the right set, the domain of on one side and a set holding its outputs on the other. Take it on too small a set and the composition would lose inputs and become a different function.
Order matters, but not never
The one law that addition has and composition lacks is commutativity. For numbers, always. For functions, and are usually different, and Worked Example 1 already showed why: running the same two machines in opposite orders can produce different outputs. With and ,
and these differ by , which is zero only at the single point . So here.
But “usually different” is not “never equal,” and the difference is worth stating exactly, because overshooting it is the classic error. Some pairs genuinely commute. Take the two translations and . Then
and the same works for any two translations and , since both orders give and addition of the shifts does not care about order. So the correct statement names both cases: composition is not always commutative. For a general pair , while for special pairs the two are equal. Writing “composition is never commutative” is simply false, as the translations show; commuting is the exception, not the rule.
A little vocabulary ties the laws together. An operation that is associative and has an identity, but need not supply an inverse for every element or commute, gives its objects the structure algebraists call a monoid. Under composition the functions form one such monoid. The missing piece, an inverse that undoes a function, is what the next lesson supplies for the functions that have one.
Check your understanding
For which pair do the two compositions agree, for every ?
Two translations always commute, because you can add the two shifts in either order.
Each other pair fails: for and , but ; for and , the orders give and ; for and , they give and .
The domain of a composition
Here is the idea the substitution procedure hides, and it is the most important thing in the lesson. When you build , two things must be true for the answer to exist: must accept , and must accept the number that comes out. Writing that down gives the domain of the composition.
The domain of #
By definition , so this value exists exactly when every step inside it is legal. Reading from the inside out, first must be defined, which requires . Given that, is then applied to the number , which is legal exactly when . Both conditions must hold, and if they do the value exists, so
This is not . The second condition constrains , an output of , so testing it requires knowing which numbers actually produces, the range of , not its domain. A value of can lie in both and yet be excluded, because escapes . The reverse also happens: a value of outside can still belong, as long as and .
So computing the domain of a composition is where the range of the inner function finally earns its keep. Two examples make the point, and the second is the payoff of the whole chapter’s insistence that the domain is part of a function’s data.
Worked example 2 A square root inside a reciprocal
Let and . Find a formula for and its domain.
The formula is a direct substitution:
Now the domain. First must accept , and needs . Second must accept the output , and rejects only the input , so we need . Since exactly when ,
Compare that with the wrong shortcut. The intersection would throw out (the value forbids) and keep . The truth is the reverse: is fine, because , while is excluded, because is the one input cannot take. The excluded input is found through the range of , not by intersecting the two domains.
Worked example 3 When the formula lies about the domain
Let and . Find , and decide whether it is the identity function.
Substituting gives a formula that simplifies all the way down:
The formula is just , so it is tempting to say is the identity. It is not. Its domain is
since requires and accepts every real output. So is the rule on the domain , and the identity function has domain all real numbers. By Function Notation’s equality test, which demands the same domain and not merely the same formula, these are different functions. The simplified threw away the record of where refused to run, and only the domain remembers it.
The other order behaves differently still. Here , defined for every real because always, so is all real numbers while is only . Neither composition is the identity on all of , and the two even have different domains, a reminder that and are in general different sets. Whether these two rules “undo” each other, and what that requires, is the business of the next lesson; here we only read off the domains.
Check your understanding
Let and . What is the domain of ?
You need , so , and also , so .
So remove , leaving with . The tempting is the intersection , the wrong rule; is allowed since .
Decomposing a function, and why the answer is not unique
Composition also runs backward as a question. Given a function , can you write it as for simpler pieces and ? This is decomposition, and it is the move that lets you see a complicated rule as a short pipeline of easy steps.
Take . The natural split peels off the outermost operation, the square root, and calls the inside a separate step: let and . Then
But this is not the only way, and that is the important part. Here are two more decompositions of the very same :
All three are correct, since each composes to . So “decompose ” has many right answers, not one, exactly as the previous lesson’s “which transformation produced this graph” had many. When a problem asks you to decompose a function it is asking for a valid split. Among the valid splits there is usually a most natural one, peel off the outermost operation, but no split is the unique correct answer. A question that treats one decomposition as “the” answer has no single answer, so we never phrase it that way.
Worked example 4 Two decompositions of one function
Write as a composition in two genuinely different ways.
The natural split peels off the cube. Let be the inside and be the cube:
A different split absorbs the doubling into the inner step and leaves the subtraction with the cube. Let and :
Both are valid decompositions of the same . Neither is more correct than the other; they simply draw the line between “inner step” and “outer step” in different places. A later course leans on exactly this idea, composing the rates of change of the pieces along a decomposition to differentiate , the chain rule. The point here is only that the decomposition that course walks along is a choice, not a fixed feature of .
Transformations were compositions all along
The previous lesson wrote every transformed graph in the shape
and split it into an inside that acts on the input and an outside that acts on the output. Name those two pieces as functions. Let
Then is the input map, is the output map, and the transformed rule is a composition of three functions:
The transformation was a composition the whole time. Reading right to left, acts first, then , then , which is exactly the story the previous lesson told: the inside happens before , and the outside after. Two of that lesson’s hardest points are now single facts about composition.
Its discovery that “stretch then shift” differs from “shift then stretch” is the non-commutativity of composition. Take the output maps “stretch by ,” written , and “shift up ,” written . Stretching then shifting is , and shifting then stretching is :
These are different because and do not commute, the same reason in general. The order of two transformations is nothing but the order of a composition, and composition does not let you swap that order for free.
Its other rule, that input maps “run backward because you solve for ,” is the statement that is applied first. In the rightmost map acts before , so to find which produces a given input to you must undo , that is solve for . Solving is undoing the first-applied map, and on the input side the first-applied map is . So the whole previous lesson was a special case of this one. Transforming a graph is composing with an input map on one side and an output map on the other, and every ordering subtlety there was composition’s non-commutativity here.
Worked example 5 A transformation read as a composition
Write in the form , and identify and .
Factor the inside so it matches , and read the outside directly:
Now check that composing them rebuilds the rule. Applying first, then , then :
So the transformation is the composition with acting on the input and acting on the output. The input map sits on the right because it acts first, exactly the “solve for ” order of the previous lesson.
Iterating a function, and a warning about squared
Because composition is associative, composing a function with itself repeatedly is unambiguous, and it has its own notation. Write
and so on, the small superscript counting how many times is applied. Read : apply , then apply again to the result.
Here is the notation warning. That superscript clashes with the other thing a superscript can mean, squaring the output, . The two are different functions. For ,
while
and these are different functions. By Function Notation’s equality test, coinciding at a stray input is not the same as being equal. Here the two functions meet only at , where both equal , and differ everywhere else. Which meaning carries is a matter of convention, and this lesson uses for the composition ; when we mean the square of the output we write . One more warning for the next lesson: there will mean the inverse of under composition, the function that undoes it, and it will never mean . A superscript on a function name is about composition, not multiplication.
Worked example 6 Iterating a linear function
Let . Compute and .
Apply to , wrapping the whole input in the rule:
Apply once more, now to :
A pattern is already visible: each step doubles the coefficient and the constant follows, giving , which reads , , for . None of these equals the output square , which is not even linear; iterating a function and squaring its value are unrelated operations that happen to share a symbol.
Combining functions without chaining them
Composition is not the only way to build a new function from two others, and it should not be confused with the arithmetic ways. You can add, subtract, multiply, or divide two functions by combining their outputs at each input, , , and . These evaluate both functions at the same and then combine the two numbers, so both functions see the original input. Composition is different in kind: it chains them, feeding the output of one as the input of the other, so only sees and sees . The domain rules differ to match. A sum or product is defined where both functions are, , the very intersection that is the wrong answer for composition. A quotient additionally removes the inputs where . These arithmetic combinations are a lesson of their own, studied in an earlier course. The point here is only that combining outputs and chaining inputs are not the same operation, and composition is the one this lesson is about.