Composition: one function after another
Take and . Feed 3 into to get 9, then feed 9 into to get 19. That two-step machine is the composition of with .
Rule: Composition
Read as " after ". Work from the inside out: apply first, then apply to the result.
The same two machines in both orders. Squaring then doubling gives 19; doubling then squaring gives 49.
The order matters. , but . A table at a few inputs shows the two compositions are different functions:
| 0 | 1 | 2 | 3 | |
|---|---|---|---|---|
| 1 | 3 | 9 | 19 | |
| 1 | 9 | 25 | 49 |
For a formula, substitute the whole inner function, brackets and all. , while , which multiplies out to . The two formulas agree only at and .
Sometimes the order does not matter. Adding 2 and adding 5 give in either order. That is the exception, so always check.
Try it
compose(outer, inner) returns a new function that applies inner and then outer. Functions are values in Python: you can pass them in and hand them back, as the exercise in lesson 1.1.4 does.
The two lists are the rows of the table.
Units chain together
A car at 80 km per hour has gone km after hours. It burns litres of fuel over km. Then litres after hours.
The units run hours, then km, then litres. After 5 hours the car has gone 400 km and used 24 litres. The other order, , would feed litres into a function that expects hours: it means nothing.
Which inputs a composition accepts
The inner output must be an allowed input of the outer function. Take and . accepts every number, but needs , so its domain is .
The other order, , needs only .
This also explains the sideways shifts of lesson 1.1.2. is applied after the inner function : a sideways shift is a composition.
Try it
NumPy returns nan where the inner output falls outside the outer domain. Here both orders run at .
fails at 0 and gives 0, 2 and 3 after it. works everywhere on ; np.round(…, 4) keeps its decimals to 4 places.
Inner and outer
Reading a formula as a composition means finding its last step. Ask what you would compute last if you evaluated it at a number.
- : first , then the 5th power. The inner function is and the outer is , with standing for whatever the inner gives.
- : inner , outer .
- : inner , outer . That is from above.
The split is a way of reading, not a new rule. Lesson 2.3.3 uses it to find the slope of a composition, the chain rule.
Inverse functions: running backwards
doubles its input and adds 3. To undo it, subtract 3 and then halve: undo the steps in reverse order, as in lesson 0.3.2. That undoing function is the inverse of , written : here .
| 0 | 1 | 2.5 | 10 | |
|---|---|---|---|---|
| 3 | 5 | 8 | 23 | |
| 0 | 1 | 2.5 | 10 |
Rule: Inverse function
The inverse sends each output back to the input it came from. The is a label, not a power: is not .
To find a formula, write and make the subject. For : subtract 3, then divide by 2, giving . Then, by habit, rename the input back to .
The reciprocal is a different thing. Here , because . But .
Units swap too
The inverse swaps inputs and outputs, units included. The fuel rule takes km to litres. Its inverse, , takes litres back to km: 30 litres cover 500 km.
Domain and range swap
Lesson 1.1.1 solved and got . That is the inverse: if , then . For example, and .
The inverse accepts only what can produce. has domain and range , so has domain and range . The formula would accept , but does not.
Rule: Domain and range of an inverse
Running backwards turns outputs into inputs, so the two sets trade places.
Try it
Check an inverse by going there and back. For every input, returns the same input.
SymPy does the rearranging: solve makes the subject. It writes as , and returns for the square root.
When an inverse exists
An inverse can only exist if no two inputs share an output. sends both and 2 to 4, so an inverse would not know which one to send 4 back to.
Rule: Horizontal line test
A function has an inverse exactly when no horizontal line crosses its graph twice. Such a function is called one-to-one.
Every straight line that is not flat passes, and so does : only at 2, and only at . A flat line such as fails as badly as possible, since every input gives the same output.
A function that fails can often be fixed by shrinking its domain. Keep only and passes, with inverse . Keep only instead and the inverse is , which sends 9 back to .
The horizontal line meets twice, so has no inverse. Kept to , it does: is its mirror image in , and becomes .
The mirror in
The graph of is the graph of mirrored in the line . Swapping inputs and outputs swaps the two coordinates of every point: on becomes on . Lesson 1.4.3 meets the same mirror between and , the logarithm defined as an inverse.
Try it
The cell checks the inverse of both ways, and the mirror pair.
g_inv(g(7)) returns 7; g(g_inv(5)) returns 5. at 2 and at 4 swap the same two numbers.
Case study 1.3.5 uses an inverse from finance: a bond's yield is read back from its price.
Common mistakes
- Composing in the wrong order. applies first.
- Dropping brackets when substituting. , not .
- Forgetting the domain of a composition. needs , even though accepts every number.
- Reading as a reciprocal. undoes ; is something else.
- Inverting a function that is not one-to-one. Shrink the domain first, and say which part you kept.
- Keeping the formula's domain for the inverse. accepts only the range of , .
Composition and inverses
0 of 12 correct
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
How to type answers
- Powers with
^:x^7,2^(1/3),a^-2. - Multiply with
*or by writing side by side:3x^2,2(x+1). ln(x)is the natural log,log(x, 2)is log base 2,eis Euler's number,sqrt(x)is a square root.sin(x),cos(x)andtan(x)take radians; writepifor π andsin(x)^2for sin²x.- Your first answer to each question is saved: it counts towards your score and brings the question back for review.
- Exact answers like
ln(20)/ln(3)are best. Decimals need about 4 significant figures.
Summary card
- : apply , then . Order matters, units pass along, and the inner output must be in the outer domain.
- To split a formula, find its last step: that is the outer function, and what it acts on is the inner.
- undoes : . It is not . Find it by writing and making the subject.
- An inverse exists when no horizontal line meets the graph twice; otherwise shrink the domain.
- The domain of is the range of , and the other way round. Its graph is the graph of mirrored in .