Int 3 for Programmers

Functions, transformations, composition and inverses

15 / 396
Contents

Contents

Int 3 for Programmers

0 of 396 complete

10 min read

Running a function backwards

Inverses from a table, from a graph, and by swapping x and y in the equation.

A currency converter turns pounds into euros. Standing at the other counter you want the opposite: given the euros, how many pounds was that? The second machine undoes the first, and it is built from the same information.

Start with a function stored as a table and reverse the lookup by hand.

Try CodePython

Change the value for key 4 from 14 to 8 and run it again. The backwards table quietly loses an entry, and the next lesson is about why.

Every pair got turned round. Where the original said 3 goes to 11, the reversed one says 11 goes to 3. Sending a value forwards and then backwards returns it unchanged.

The reversed function is called the inverse of the original, and it is written f−1f^{-1}, said as f inverse. Its rule is exactly the promise you watched: it takes an output of ff and returns the input that produced it.

f(a)=bmeans exactly the same asf−1(b)=af(a) = b \quad \text{means exactly the same as} \quad f^{-1}(b) = a
One statement, two ways of writing it. The pair (a, b) becomes the pair (b, a).

On a graph: reflect over the line y = x

If (a,b)(a, b) is on the graph of ff, then (b,a)(b, a) is on the graph of f−1f^{-1}. Swapping the two coordinates of a point is exactly what reflecting it over the line y=xy = x does. Run it and check the distances.

Try CodePython

Add the point (4, 4) to the list and run it again. It is its own reflection, because it already sits on the line y=xy = x.

The midpoint of a point and its partner always has equal coordinates, so it lies on y=xy = x. That is what makes the reflection exact rather than approximate: the line y=xy = x is the mirror.

A line and its inverse, either side of the mirror
f(x)=2x+(−3)f−1(x)=x−(−3)2f(x) = 2x + (-3) \qquad f^{-1}(x) = \frac{x - (-3)}{2}
-6-3036-6-3036
the inversethe mirror y = x
f(2)f(2)
1
Inverse applied to that
2

Drag a and b. The two solid lines are always mirror images in the dashed one, and the second output always comes back to 2.

From the equation: swap and solve

The algebra follows the same swap. Since the pairs (a,b)(a,b) turn into (b,a)(b,a), exchange xx and yy in the equation and then rearrange to get yy on its own.

One worked example in full. Find the inverse of f(x)=3x−4f(x) = 3x - 4.

  1. Write it with yy: y=3x−4y = 3x - 4.
  2. Swap the letters: x=3y−4x = 3y - 4.
  3. Add 4 to both sides: x+4=3yx + 4 = 3y.
  4. Divide both sides by 3: y=x+43y = \frac{x + 4}{3}.
  5. Write it in the proper notation: f−1(x)=x+43f^{-1}(x) = \frac{x + 4}{3}.

Test it on a number. f(5)=15−4=11f(5) = 15 - 4 = 11, and f−1(11)=11+43=153=5f^{-1}(11) = \frac{11 + 4}{3} = \frac{15}{3} = 5. The 5 came back.

There is a second way to think about the same work, which some people find faster: list what ff does to the input in order, then undo each step in the opposite order. For 3x−43x - 4 the steps are multiply by 3, then subtract 4. Undone backwards: add 4, then divide by 3. That is the rule derived above.

Try CodePython

Change f_inverse to (x - 4) / 3, an easy slip, and run it again. Nothing comes back to where it started.

One more consequence of swapping the pairs, and it is examined often: the domain of f−1f^{-1} is the range of ff, and the range of f−1f^{-1} is the domain of ff. The inputs and outputs have traded places, so their sets trade places too.

An example makes that concrete. If ff has domain [0,∞)[0, \infty) and range [2,∞)[2, \infty), then f−1f^{-1} has domain [2,∞)[2, \infty) and range [0,∞)[0, \infty). Handing f−1f^{-1} the number 1 is meaningless, because no input to ff ever produced 1 in the first place.

The undoing-the-steps view also explains why the steps come back in reverse. If getting dressed is socks and then shoes, undressing is shoes and then socks. Since ff multiplies by 3 and then subtracts 4, its inverse adds 4 and then divides by 3, and doing those two in the other order gives a different rule that does not undo anything.

A function has f(2)=9f(2) = 9. What is f−1(9)f^{-1}(9), and what is f−1(2)f^{-1}(2)?

f−1(9)=2f^{-1}(9) = 2, straight from the definition: 9 was produced by 2. f−1(2)f^{-1}(2) cannot be worked out from what you were given; you would need to know which input produces the output 2, and nothing here says. Answering 9 is the trap.

Check yourself

What is the inverse of f(x)=x5+1f(x) = \frac{x}{5} + 1?

All lessons in Int 3 for Programmers