Combining and Composing Functions
Learning goals
- Add, subtract, multiply and divide two functions at a shared input
- Exclude inputs where the divisor function is zero
- Compose with , inner first
- Substitute the whole inner rule to get a composed formula
- Show that usually differs from
- Require an input allowed into both functions in turn
Building new functions by arithmetic
Suppose two functions share the same input. Say gives the distance in metres that one runner has covered after seconds, and gives a second runner’s distance, starting from a two-metre head start. At any moment you can ask about the two runners together: their combined distance is , and the gap between them is . Nothing exotic is happening. You evaluate each function at the same input, then combine the two outputs with ordinary arithmetic. That one idea defines four brand-new functions:
Read the left side of each line as the name of a single new function. The symbol is one function whose rule is “evaluate , evaluate , and add the results.” To find its output at any input, you do exactly that.
The first three combinations accept every input that both and accept, so they need no special care. The quotient is the one that does. You already know that division by zero is undefined, so the fraction has no value at any input where the denominator equals zero. Those inputs have to be thrown out, even when and are both perfectly happy there. So the quotient is defined only where . This is not a new rule to memorize; it is the old ban on dividing by zero, now applied to the output of .
Worked example 1 Adding, subtracting, multiplying, and dividing two functions
Let and . Build all four combinations, and find where the quotient is defined.
For the sum, subtraction, and product, substitute the two rules and simplify:
For the quotient, write the fraction and then find the input that would make the denominator zero:
So is defined for every input except . You can also evaluate any combination at a number. At , for instance, and , so and .
Check your understanding
If and , what is ?
Add the two rules at the same input, then combine like terms.
The function just means 'evaluate , evaluate , and add the two outputs.'
Composing: feeding one function into another
Combining with arithmetic keeps the two functions side by side. Composition instead stands them in a line. Picture a small factory with two machines. The first machine takes your raw input and produces a part; the second machine takes that part and finishes it. The output of the first becomes the input of the second.
Make it concrete with and . Start with an input, say . Run first: . Now take that result, , and run it through : . The end product of the two-step process is . Written on one line, this is : the inner function acts on , and acts on whatever hands it.
This two-step operation is composition, and it has its own symbol. The composition of and is written (read ” composed with ,” or ” after ”), and it is defined by
The little ring is not multiplication and not the letter o; it is the composition sign. The right-hand side, , is the form you actually calculate with.
Which function runs first? The nested notation answers the question on its own. In the input is wrapped inside , and then sits inside the parentheses of . Just as with nested parentheses in arithmetic, you work from the inside out: whatever is deepest gets evaluated first. So runs first on the raw input, and runs second on ‘s output. The inner function, the one written closest to the input, always goes first, even though in the name it is written second.
Worked example 2 Composing at a number in both orders
Let and . Compute and .
For , work from the inside out. Run on first, then run on the result:
So . Now reverse the order. For , run on first, then run :
So . Same two functions, same starting number, but and are nowhere near each other. The order in which you apply the functions clearly matters, a point the next section makes exact.
Finding a formula for a composition
Evaluating at one input is fine, but usually you want a single formula for that works at every input at once. The recipe is the substitution you have used since your first algebra lesson. To build , take the entire rule for and drop that rule into wherever expects its input.
Worked example 3 Finding a formula for and
Let and . Find formulas for and .
For , substitute the whole rule into in place of its input, then expand the square:
For , substitute the whole rule into in place of its input:
These two formulas are not the same function. As a quick check, evaluate each at : and , exactly the two numbers from the previous worked example.
Check your understanding
If and , what is ?
Work from the inside out. First run on the input .
Then feed that output into .
So . The choice is , which skips the inner function.
Order matters: a composition is not commutative
Look back at the last two worked examples. In both, swapping the order changed the answer: but , and the formula against . This is not a fluke of one example. Composition is not commutative: in general and are different functions, and reversing the order changes the result. This is the single most important idea in the lesson, so it is worth understanding why it happens rather than just noting that it does.
The reason is exactly the assembly-line picture. In the last machine to touch the number is , so the final answer is always something produced. In the last machine is , so the final answer is always something produced. Since and do different jobs, the two lines hand you different products. Squaring and then adding four is not the same as adding four and then squaring: puts the four in at the very end. By contrast, adds the four first and then squares the whole thing, which spreads the four through the extra middle term . The four enters at a different stage, and the machine that comes after it treats it differently.
The domain of a composition
Because a composition runs in two steps, an input has to survive both to be allowed. First it must be a legal input for , because runs first. Then the number has to be a legal input for , because runs on that output. If either step fails, never gets a value. Here is that reasoning stated exactly.
Which inputs a composition accepts#
To evaluate you carry out two steps in sequence, and the composite has a value exactly when both steps succeed.
The first step computes . For this to produce a number at all, must be an allowed input of , that is, must lie in the domain of . If is not in the domain of , then does not exist, and there is nothing to hand to . In that case the composite is undefined before even gets a turn.
The second step applies to the number . Even when exists, can only act on it if is itself an allowed input of . In other words, must lie in the domain of . If is a value that rejects, such as a number that would make divide by zero, then is undefined again.
So has a value if and only if both conditions hold at once. The first is that lies in the domain of , and the second is that lies in the domain of . Every input that fails either test is excluded from the domain of , and every input that passes both is included. That two-part rule is not extra to memorize; it is just the two-step process read out loud.
The second half of that rule is the sneaky one, because it can exclude an input that looks perfectly innocent to the inner function.
Worked example 4 The domain of a composition
Let and . Find and its domain.
Substitute into to get the formula:
Now apply the two-part rule. The inner function accepts every number, so the first test excludes nothing. The outer function rejects only the input , so the second test demands :
Watch what happens at . The inner function is perfectly happy there, since . But that output, , is exactly the one value cannot take, because is undefined. So passes the first test and fails the second. Failing the second test throws out of the domain, even though that input never looked dangerous in the rule for . A safe input like sails through: and then . The domain of is all numbers except .
Check your understanding
Let and . Which input is NOT in the domain of ?
An input survives only if accepts it and then accepts 's output. Here accepts every number, so look for the input whose output rejects. Since cannot take , find where .
At the inner output is , which cannot use, so is excluded.
Composition models a two-step process
Composition is not just a symbol game. Any time one quantity depends on a second, which in turn depends on a third, you have a composition waiting to be written down. Discounts followed by fees, readings passed through a converter, a shape whose size grows with time: each is one function feeding the next.
Worked example 5 A discount followed by shipping
An online store takes percent off every item, then adds a flat shipping fee of dollars to the discounted price. Model the final price as a composition, and find it for an item that normally costs dollars.
Name the two steps. Taking percent off leaves percent of the price, so the discount function is . Adding shipping to a price is . The store discounts first and then adds shipping to the discounted price, so shipping is the outer function and the final price is :
For an item with :
The final price is dollars. Order matters here too, exactly as before. Had the store instead added shipping first and then discounted, the result would be , which at gives dollars. The two policies are genuinely different, and the composition records which one the store actually uses.