SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 1.1.1 What a function is: domain, range and notationConcept · 25 min
      2. 1.1.2 Transformations and piecewise functionsConcept · 30 min
      3. 1.1.3 Composition and inverse functionsConcept · 25 min
      4. 1.1.4 Practice set: functionsPractice set · 20 min
      5. 1.1.5 Case study: option payoff diagramsCase study · 30 min

Level 1, Precalculus 1.1 Functions and graphs Lesson 3 of 5

ConceptLesson 1.1.3 in Level 1, Precalculus. About 25 minutes.

Composition and inverse functions

Composition: one function after another

Take f(x)=2x+1f(x) = 2x + 1 and g(x)=x2g(x) = x^2. Feed 3 into gg to get 9, then feed 9 into ff to get 19. That two-step machine is the composition of ff with gg.

Rule: Composition

(f∘g)(x)=f(g(x))(f \circ g)(x) = f\big(g(x)\big)

Read f∘gf \circ g as "ff after gg". Work from the inside out: apply gg first, then apply ff to the result.

The same two machines in both orders. Squaring then doubling gives 19; doubling then squaring gives 49.

The order matters. f(g(3))=f(9)=19f(g(3)) = f(9) = 19, but g(f(3))=g(7)=49g(f(3)) = g(7) = 49. A table at a few inputs shows the two compositions are different functions:

xx0123
f(g(x))f(g(x))13919
g(f(x))g(f(x))192549

For a formula, substitute the whole inner function, brackets and all. f(g(x))=2x2+1f(g(x)) = 2x^2 + 1, while g(f(x))=(2x+1)2g(f(x)) = (2x + 1)^2, which multiplies out to 4x2+4x+14x^2 + 4x + 1. The two formulas agree only at x=0x = 0 and x=−2x = -2.

Sometimes the order does not matter. Adding 2 and adding 5 give x+7x + 7 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.

⌘/Ctrl + Enter runs the cell

Units chain together

A car at 80 km per hour has gone g(t)=80tg(t) = 80t km after tt hours. It burns f(d)=0.06df(d) = 0.06d litres of fuel over dd km. Then f(g(t))=0.06×80t=4.8tf(g(t)) = 0.06 \times 80t = 4.8t litres after tt 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, g(f(t))g(f(t)), 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 f(x)=xf(x) = \sqrt{x} and g(x)=x−4g(x) = x - 4. gg accepts every number, but f(g(x))=x−4f(g(x)) = \sqrt{x - 4} needs x−4≥0x - 4 \ge 0, so its domain is x≥4x \ge 4.

The other order, g(f(x))=x−4g(f(x)) = \sqrt{x} - 4, needs only x≥0x \ge 0.

This also explains the sideways shifts of lesson 1.1.2. x−4\sqrt{x - 4} is x\sqrt{x} applied after the inner function x−4x - 4: 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 x=0,4,8,13x = 0, 4, 8, 13.

x−4\sqrt{x - 4} fails at 0 and gives 0, 2 and 3 after it. x−4\sqrt{x} - 4 works everywhere on x≥0x \ge 0; np.round(…, 4) keeps its decimals to 4 places.

⌘/Ctrl + Enter runs the cell

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.

  • (3x+1)5(3x + 1)^5: first 3x+13x + 1, then the 5th power. The inner function is 3x+13x + 1 and the outer is u5u^5, with uu standing for whatever the inner gives.
  • x2+1\sqrt{x^2 + 1}: inner x2+1x^2 + 1, outer u\sqrt{u}.
  • 2x2+12x^2 + 1: inner x2x^2, outer 2u+12u + 1. That is f(g(x))f(g(x)) 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

f(x)=2x+3f(x) = 2x + 3 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 ff, written f−1f^{-1}: here f−1(x)=x−32f^{-1}(x) = \frac{x - 3}{2}.

xx012.510
f(x)=2x+3f(x) = 2x + 335823
f−1(f(x))f^{-1}(f(x))012.510

Rule: Inverse function

f−1(f(x))=xf(f−1(y))=y\begin{gathered} f^{-1}\big(f(x)\big) = x \\ f\big(f^{-1}(y)\big) = y \end{gathered}

The inverse sends each output back to the input it came from. The −1-1 is a label, not a power: f−1(x)f^{-1}(x) is not 1f(x)\frac{1}{f(x)}.

To find a formula, write y=f(x)y = f(x) and make xx the subject. For y=2x+3y = 2x + 3: subtract 3, then divide by 2, giving x=y−32x = \frac{y - 3}{2}. Then, by habit, rename the input back to xx.

The reciprocal is a different thing. Here f−1(5)=1f^{-1}(5) = 1, because f(1)=5f(1) = 5. But 1f(5)=113\frac{1}{f(5)} = \frac{1}{13}.

Units swap too

The inverse swaps inputs and outputs, units included. The fuel rule f(d)=0.06df(d) = 0.06d takes km to litres. Its inverse, f−1(L)=L0.06f^{-1}(L) = \frac{L}{0.06}, takes litres back to km: 30 litres cover 500 km.

Domain and range swap

Lesson 1.1.1 solved x−3=y\sqrt{x - 3} = y and got x=y2+3x = y^2 + 3. That is the inverse: if g(x)=x−3g(x) = \sqrt{x - 3}, then g−1(x)=x2+3g^{-1}(x) = x^2 + 3. For example, g(7)=2g(7) = 2 and g−1(2)=7g^{-1}(2) = 7.

The inverse accepts only what gg can produce. gg has domain [3,∞)[3, \infty) and range [0,∞)[0, \infty), so g−1g^{-1} has domain [0,∞)[0, \infty) and range [3,∞)[3, \infty). The formula x2+3x^2 + 3 would accept −2-2, but g−1g^{-1} does not.

Rule: Domain and range of an inverse

domain of f−1=range of frange of f−1=domain of f\begin{gathered} \text{domain of } f^{-1} = \text{range of } f \\ \text{range of } f^{-1} = \text{domain of } f \end{gathered}

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, f−1(f(x))f^{-1}(f(x)) returns the same input.

SymPy does the rearranging: solve makes xx the subject. It writes y−32\frac{y - 3}{2} as y2−32\frac{y}{2} - \frac{3}{2}, and returns y2+3y^2 + 3 for the square root.

⌘/Ctrl + Enter runs the cell

When an inverse exists

An inverse can only exist if no two inputs share an output. x2x^2 sends both −2-2 and 2 to 4, so an inverse would not know which one to send 4 back to.

Rule: Horizontal line test

each horizontal line meetsthe graph at most once\begin{gathered} \text{each horizontal line meets} \\ \text{the graph at most once} \end{gathered}

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 x3x^3: x3=8x^3 = 8 only at 2, and x3=−8x^3 = -8 only at −2-2. A flat line such as y=5y = 5 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 x≥0x \ge 0 and x2x^2 passes, with inverse x\sqrt{x}. Keep only x≤0x \le 0 instead and the inverse is −x-\sqrt{x}, which sends 9 back to −3-3.

The horizontal line y=4y = 4 meets x2x^2 twice, so x2x^2 has no inverse. Kept to x≥0x \ge 0, it does: x\sqrt{x} is its mirror image in y=xy = x, and (2,4)(2, 4) becomes (4,2)(4, 2).

The mirror in y=xy = x

The graph of f−1f^{-1} is the graph of ff mirrored in the line y=xy = x. Swapping inputs and outputs swaps the two coordinates of every point: (2,4)(2, 4) on x2x^2 becomes (4,2)(4, 2) on x\sqrt{x}. Lesson 1.4.3 meets the same mirror between exe^x and ln⁡x\ln x, the logarithm defined as an inverse.

Try it

The cell checks the inverse of x−3\sqrt{x - 3} both ways, and the mirror pair.

g_inv(g(7)) returns 7; g(g_inv(5)) returns 5. x2x^2 at 2 and x\sqrt{x} at 4 swap the same two numbers.

⌘/Ctrl + Enter runs the cell

Case study 1.3.5 uses an inverse from finance: a bond's yield is read back from its price.

Common mistakes

  1. Composing in the wrong order. f(g(x))f(g(x)) applies gg first.
  2. Dropping brackets when substituting. g(f(x))=(2x+1)2g(f(x)) = (2x + 1)^2, not 2x+122x + 1^2.
  3. Forgetting the domain of a composition. x−4\sqrt{x - 4} needs x≥4x \ge 4, even though x−4x - 4 accepts every number.
  4. Reading f−1f^{-1} as a reciprocal. f−1(x)f^{-1}(x) undoes ff; 1f(x)\frac{1}{f(x)} is something else.
  5. Inverting a function that is not one-to-one. Shrink the domain first, and say which part you kept.
  6. Keeping the formula's domain for the inverse. g−1(x)=x2+3g^{-1}(x) = x^2 + 3 accepts only the range of gg, x≥0x \ge 0.

Composition and inverses

0 of 12 correct

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6.
  7. 7.
  8. 8.
  9. 9.
  10. 10.
  11. 11.
  12. 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, e is Euler's number, sqrt(x) is a square root.
  • sin(x), cos(x) and tan(x) take radians; write pi for π and sin(x)^2 for 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

  • (f∘g)(x)=f(g(x))(f \circ g)(x) = f(g(x)): apply gg, then ff. 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.
  • f−1f^{-1} undoes ff: f−1(f(x))=xf^{-1}(f(x)) = x. It is not 1/f(x)1/f(x). Find it by writing y=f(x)y = f(x) and making xx the subject.
  • An inverse exists when no horizontal line meets the graph twice; otherwise shrink the domain.
  • The domain of f−1f^{-1} is the range of ff, and the other way round. Its graph is the graph of ff mirrored in y=xy = x.

Free further reading

Optional. This lesson covers what you need; these add more examples and practice. All are free to read.