Int 3 for Programmers

Functions, transformations, composition and inverses

17 / 396
Contents

Contents

Int 3 for Programmers

0 of 396 complete

8 min read

Proving that two functions undo each other

The composition test, done both ways, and why one way is not enough.

Deriving an inverse involves several steps of rearranging, and any of them can go wrong. There is a check that catches the mistake in one line, and it is also the definition an exam asks you to quote.

The idea is the round trip. Send a number through one function and then the other, and see whether it comes back unchanged. Run it on a candidate that is correct and on one that is not.

Try CodePython

Change bad to (x + 2) / 4 and run it again. A wrong denominator fails on every input except one. Which input survives, and why is it not proof of anything?

The good candidate returned every input exactly. The bad one was out by a fixed amount each time. That round trip is the definition, written with the composition notation from earlier in the section.

f(g(x))=xfor every x in the domain of gf\bigl(g(x)\bigr) = x \quad \text{for every } x \text{ in the domain of } g
g(f(x))=xfor every x in the domain of fg\bigl(f(x)\bigr) = x \quad \text{for every } x \text{ in the domain of } f
Both statements are required. Two functions that satisfy both are inverses of each other.

One worked example in full. Show that f(x)=5x−2f(x) = 5x - 2 and g(x)=x+25g(x) = \frac{x+2}{5} are inverses.

  1. First direction: f(g(x))=5⋅x+25−2f(g(x)) = 5 \cdot \frac{x+2}{5} - 2.
  2. The 5 outside cancels the 5 on the bottom, leaving (x+2)−2=x(x + 2) - 2 = x.
  3. Second direction: g(f(x))=(5x−2)+25g(f(x)) = \frac{(5x - 2) + 2}{5}.
  4. The −2-2 and the +2+2 cancel, leaving 5x5=x\frac{5x}{5} = x.
  5. Both compositions give xx, so the two functions are inverses.

Why both directions are needed

It looks as though one check should be enough, and for the tidy functions in this course it usually is. It is not enough in general, and the reason is the restriction problem from the last lesson. Run it.

Try CodePython

Change the second list to [0, 1, 2, 5] and run it again. With the negatives removed the second direction works too, which is exactly what restricting the domain achieves.

The first direction is perfect: squaring a square root gives the number back every time. The second direction fails on every negative input, returning 3 for -3 and 1 for -1. A single successful direction proves nothing on its own, so both are written out.

The check earns its keep in two places. After deriving an inverse by swapping and rearranging, one composition catches any slip in the rearranging in a single line. And when a question asserts that two functions are inverses and asks you to show it, the compositions are the whole of the expected answer; no swapping or rearranging is needed at all.

One more worked pair, done quickly. Are f(x)=x4+2f(x) = \frac{x}{4} + 2 and g(x)=4x−8g(x) = 4x - 8 inverses? First direction: f(g(x))=4x−84+2=(x−2)+2=xf(g(x)) = \frac{4x - 8}{4} + 2 = (x - 2) + 2 = x. Second direction: g(f(x))=4(x4+2)−8=x+8−8=xg(f(x)) = 4\left(\frac{x}{4} + 2\right) - 8 = x + 8 - 8 = x. Both collapse, so yes.

Are f(x)=x+4f(x) = x + 4 and g(x)=x−4g(x) = x - 4 inverses?

Yes. f(g(x))=(x−4)+4=xf(g(x)) = (x - 4) + 4 = x, and g(f(x))=(x+4)−4=xg(f(x)) = (x + 4) - 4 = x. Both directions collapse to xx with no restriction needed, since both functions accept every real number.

Check yourself

A student checks that f(g(2))=2f(g(2)) = 2 and concludes that ff and gg are inverses. What is wrong with that?

All lessons in Int 3 for Programmers