Advanced level

Composition and inverse functions

Two functions set one behind the other, and one function run backwards. See why f(g(x)) is not g(f(x)), how the monotonicity of a composition follows from its parts, when a function can be inverted at all, and why the graph of the inverse is a reflection in the line y = x.

Before you start

This topic builds on earlier ideas. Before you start, it's worth working through the lessons below — they'll make everything click:

Where this is used

Real situations where you count exactly the way this lesson teaches:

  • A currency desk with a commission
    An exchange office converts euros to zloty at g(x) = 4.30x and then takes a 2% commission, f(y) = 0.98y. A customer changing 500 € receives f(g(500)) = 0.98 · 2150 = 2107 zloty. The reverse operation answers "how many euros must I sell to get 3000 zloty": from 4.214x = 3000 we get 711.91 €, and that is precisely the inverse of the composition.
  • Rescaling temperature in a laboratory
    A sensor reports a voltage U, converted to degrees Celsius by T = 25U − 40, while the report needs Fahrenheit: F = 1.8T + 32. The composition gives F = 1.8(25U − 40) + 32 = 45U − 40, so at U = 2 V the report shows 50 °F. Inverting 45U − 40 = 100 tells the technician that 100 °F corresponds to 3.11 V.
  • Price after a discount and tax
    A shop grants a 20% discount, r(x) = 0.8x, and the till adds 23% VAT, v(y) = 1.23y. For a net price of 500 zloty the composition gives v(r(500)) = 1.23 · 400 = 492 zloty. Here the order happens not to matter, since both steps are multiplications — but with a flat discount ("minus 100 zloty") v(r(500)) = 492 while r(v(500)) = 515, a difference of 23 zloty.
  • Cryptography and the inverse key
    A simple affine cipher encodes the letter numbered x as f(x) = (5x + 8) mod 26. The recipient has to compute the inverse function: f⁻¹(y) = 21(y − 8) mod 26, because 21 is the inverse of 5 modulo 26. The letter "K", numbered 10, encrypts to 58 mod 26 = 6, and decrypting 21·(6 − 8) mod 26 = 10 returns the original — the whole mechanism is one function and its inverse.

All formulas

  • Composition of functions

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

    g first, then f — read from the inside out

  • Order matters

    fggff \circ g \neq g \circ f

    composition is not commutative

  • One-to-one

    x1x2    f(x1)f(x2)x_1 \neq x_2 \implies f(x_1) \neq f(x_2)

    the condition for an inverse to exist

  • The inverse function

    f1(f(x))=x,f(f1(y))=yf^{-1}\big(f(x)\big) = x, \qquad f\big(f^{-1}(y)\big) = y

    undoes exactly what f did

  • Roles swapped

    y=f(x)    x=f1(y)y = f(x) \iff x = f^{-1}(y)

    domain and range change places

  • The graph of the inverse

    (a,b)f    (b,a)f1(a,\, b) \in f \iff (b,\, a) \in f^{-1}

    a reflection in the line y = x

A coffee machine works in two stages: it grinds the beans, then brews them. Put beans in and a drink comes out — but the order cannot be swapped, and no cup gives the beans back. Composition and the inverse function are exactly those two questions.

Composing functions

The output of one function can be the argument of another:

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

The notation is read from the inside out: gg acts first, then ff. We call gg the inner function and ff the outer one.

Given f(x) = x² + 1 and g(x) = 2x − 3, compute f(g(4)) and g(f(4)).

The formula of a composition

Instead of computing point by point, substitute the whole inner function for the argument:

f(x)=x2+1,g(x)=2x3f(x) = x^2 + 1, \quad g(x) = 2x - 3 f(g(x))=(2x3)2+1=4x212x+10f\big(g(x)\big) = (2x-3)^2 + 1 = 4x^2 - 12x + 10 g(f(x))=2(x2+1)3=2x21g\big(f(x)\big) = 2(x^2+1) - 3 = 2x^2 - 1

Two different polynomials — formal confirmation that composition is not commutative:

fggff \circ g \neq g \circ f

The chain rule in the lesson on the derivative differentiates expressions of exactly this shape — and only now is it clear what they are.

The domain of a composition

This is where mistakes are easiest. The domain of fgf \circ g consists of those arguments xx for which:

  1. xx lies in the domain of gg, and
  2. the value g(x)g(x) lies in the domain of ff.

The second condition can narrow things sharply. For f(x)=xf(x) = \sqrt{x} and g(x)=x3g(x) = x - 3 the function gg is defined everywhere, but the composition x3\sqrt{x-3} needs x30x - 3 \ge 0, so the domain is [3,)[3,\, \infty).

Monotonicity of a composition

A composition inherits its monotonicity from its parts — and the proof is short, because it fits entirely inside the definition.

Theorem. If gg is increasing and ff is increasing, then fgf \circ g is increasing.

Proof. Take any x1<x2x_1 < x_2 in the domain of the composition.

x1<x2  g increasing  g(x1)<g(x2)  f increasing  f(g(x1))<f(g(x2))x_1 < x_2 \;\overset{g \text{ increasing}}{\Longrightarrow}\; g(x_1) < g(x_2) \;\overset{f \text{ increasing}}{\Longrightarrow}\; f\big(g(x_1)\big) < f\big(g(x_2)\big)

The inequality between the arguments passed through both functions untouched, so (fg)(x1)<(fg)(x2)(f \circ g)(x_1) < (f \circ g)(x_2). That is exactly the definition of an increasing function. \blacksquare

The same scheme with the inequalities reversed gives the remaining three cases:

ggfffgf \circ g
increasingincreasingincreasing
increasingdecreasingdecreasing
decreasingincreasingdecreasing
decreasingdecreasingincreasing

The last row surprises, but it behaves like multiplying negative numbers: two reversals cancel each other out.

One-to-one functions

For a function to be undoable, every value must come from exactly one argument:

x1x2    f(x1)f(x2)x_1 \neq x_2 \implies f(x_1) \neq f(x_2)

Such a function is called one-to-one. On a graph this is checked by the horizontal-line test: if any horizontal line meets the graph more than once, the function is not one-to-one.

The function y=x2y = x^2 on the whole line fails the test — the line y=4y = 4 hits it twice. Every strictly monotone function passes it, because a direction once chosen is never reversed.

The inverse function

For a one-to-one function there is a function f1f^{-1} that undoes ff:

f1(f(x))=x,f(f1(y))=yf^{-1}\big(f(x)\big) = x, \qquad f\big(f^{-1}(y)\big) = y

Domain and range swap roles in the process: what used to be the output becomes the input.

Mind the notation. f1f^{-1} does not mean 1f\tfrac{1}{f}. For f(x)=2xf(x) = 2x we have f1(x)=x2f^{-1}(x) = \tfrac{x}{2}, while 1f(x)=12x\tfrac{1}{f(x)} = \tfrac{1}{2x} — two entirely different functions.

Finding the formula

Three steps, always the same:

  1. write y=f(x)y = f(x);
  2. solve that equation for xx;
  3. swap the names of the variables.
Find the inverse of f(x) = 2x − 3 and give its domain.

The graph

−4−3−2−1012345678−4−3−2−1012345678xyy = xf(x) = 2x − 3f⁻¹(x) = (x + 3)/2
A function and its inverse as a pair reflected in the line y = x. The point (2, 1) on the graph of f corresponds to (1, 2) on the graph of f⁻¹ — the same numbers, swapped.

Since ff maps aba \mapsto b, the inverse maps bab \mapsto a. The point (a,b)(a,\, b) therefore goes to (b,a)(b,\, a), and swapping the coordinates is a reflection in the line y=xy = x.

When the domain has to be restricted

A function that fails the horizontal-line test is not lost — it is enough to cut part of it away.

01234567890123456789xyy = xy = x² for x ≥ 0y = √x
The parabola restricted to non-negative arguments, and the square root as its inverse. On the whole line there would be no inverse — y = 4 has both 2 and −2 as candidates.

The same move stands behind three other pairs you have met or will meet:

  • y=x2y = x^2 for x0x \ge 0 and the square root y=xy = \sqrt{x};
  • y=bxy = b^x and the logarithm y=logbxy = \log_b x — here no restriction is needed, because the exponential function is one-to-one on the whole line;
  • y=sinxy = \sin x restricted to [π2,π2]\left[-\tfrac{\pi}{2},\, \tfrac{\pi}{2}\right] and the inverse trigonometric functions, that is arcsine and its siblings.

The last case is the best test of this lesson: the sine repeats every 2π2\pi, so the equation sinx=12\sin x = \tfrac{1}{2} has infinitely many solutions. Only restricting the domain to a single full run makes the function one-to-one and therefore invertible — and the graph of arcsin\arcsin is the reflection of that restricted sine in the line y=xy = x, exactly as in the picture above.

Practice

The set checks four skills: the value of a composition f(g(x))f(g(x)) at a point (work from the inside out), the formula of a composition after substitution, the formula of an inverse function, and one value of it — the last of which needs no formula at all, only the question "for which xx does the function give this value". Formulas may be typed in any equivalent spelling: (x−3)/2 and 0.5x−1.5 are both accepted. Proving the monotonicity of a composition stays with the theorem above — its answer is a chain of reasoning, not a number.

Practice

Work through a set of exercises — they get harder as you go. At the end you'll see your score and the mistakes worth reviewing.

Exercise 1 of 8Score: 0
f(x) = −2x − 5, g(x) = −3x + 5; f(g(−2)) =

Common mistakes

  • Reading f(g(x))f(g(x)) from the left — always start with the inner function, that is with gg.
  • Assuming commutativityfgf \circ g and gfg \circ f are in general two different functions.
  • Skipping the domain of the composition — "gg is defined everywhere" is not enough; the value g(x)g(x) has to land in the domain of ff.
  • Treating f1f^{-1} as 1f\tfrac{1}{f} — it is the inverse function, not the reciprocal.
  • Inverting a function that is not one-to-one — without restricting the domain there is no inverse.
  • Forgetting the third step — after solving for xx the variables have to be renamed so that the argument is called xx again.

Formula card

Topic: Composition and inverse functions

  • Composition of functions

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

    g first, then f — read from the inside out

  • Order matters

    fggff \circ g \neq g \circ f

    composition is not commutative

  • One-to-one

    x1x2    f(x1)f(x2)x_1 \neq x_2 \implies f(x_1) \neq f(x_2)

    the condition for an inverse to exist

  • The inverse function

    f1(f(x))=x,f(f1(y))=yf^{-1}\big(f(x)\big) = x, \qquad f\big(f^{-1}(y)\big) = y

    undoes exactly what f did

  • Roles swapped

    y=f(x)    x=f1(y)y = f(x) \iff x = f^{-1}(y)

    domain and range change places

  • The graph of the inverse

    (a,b)f    (b,a)f1(a,\, b) \in f \iff (b,\, a) \in f^{-1}

    a reflection in the line y = x

−4−3−2−1012345678−4−3−2−1012345678xyy = xf(x) = 2x − 3f⁻¹(x) = (x + 3)/2
The function f(x) = 2x − 3 and its inverse f⁻¹(x) = (x + 3)/2. Each line is the reflection of the other in y = x — the point (3, 3) lies on both, because it lies on the mirror.
01234567890123456789xyy = xy = x² for x ≥ 0y = √x
The parabola y = x² restricted to non-negative arguments, and its inverse y = √x. Without the restriction there would be no inverse: y = 4 has two arguments, 2 and −2, and a function must name one.

Frequently asked questions

Related articles