There are situations in life in which it’s useful to go backwards. Imagine, for example, you’re a bank. Your computer contains a list of names (your clients) and for each name there is a number (the client’s account balance). That number is positive if the client is in credit and negative if they are in debt.

Now imagine that, unfortunately, your system has been attacked by a virus that has systematically changed the account balances of all your customers. Your IT expert can figure out what formula the virus used to change the numbers, but that’s all you know. Can you figure out the original numbers from the list of changed ones?

It depends. Say your IT expert tells you that the virus has added £1,000,000 to each account balance. In this case it’s easy to work out what the original numbers were: you simply subtract £1,000,000 from each number in the new list. But what if the virus has squared every account balance? Then you have a problem. If, for example, the changed balance of client A is £100, then their original balance could have been £10 or -£10, as each number gives you £100 when squared. You have no way of figuring out the original numbers without further information.

What you have been trying to do here is find the inverse of a function. In the first example, with the virus adding £1,000,000, the function is \[f(x) = x + 1\,000\,000\] and in the second, with the virus squaring, it is \[f(x) = x^2.\]

The inverse of \(f\) is the function \(g\) that goes the other way: given an \(f(x)\), the function \(g\) should return the original \(x\), that is, \[g(f(x))=x.\]

To find out whether a function has an inverse we need to know its domain and range (see Maths for dinner). In our example the domain contains the original account balances, which we don’t know. But since these can be negative or positive numbers, let’s take the domain to consist of all the real numbers. And let’s take the range to consist of the list of altered account balances.

A function \(f\) has an inverse if (and only if) for every element of its range (every \(y\) in the range) there is exactly one element of the domain (one \(x\) in the domain) so that \(f(x) = y\). In other words, \(f\) has an inverse if and only if it is a bijection (see Maths for dinner).

The function in the first example, \(f(x) = x + 1\,000\,000\), clearly satisfies the requirement that for every element \(y\) in the range there is exactly one element \(x\) in the domain so that \(f(x)=y\): that element is \(y-1\,000\,000.\) The function therefore has an inverse. It’s \[g(x) = x - 1\,000\,000.\]

The function in the second example, \(f(x) = x^2\), does not satisfy this property. For every positive number \(y\) in the range there are two numbers that are allocated to it by the function. These numbers are \(\sqrt{y}\) and \(-\sqrt{y}\), since \[f(\sqrt{y}^2) = f((-\sqrt{y})^2) = y.\] This is the reason why you cannot figure out the original account balances: \(f\) does not have an inverse.

A little more information about the domain, however, might help. Suppose you know that none of the customers were in debt. This restricts your domain to the positive real numbers and zero. For every number \(y\) in the range there now is exactly one number \(x\) in the domain such that \[f(x) = y.\] That number is \(\sqrt{y}\), so your inverse function is \[g(x) = \sqrt{x},\] since \[g(f(x)) = \sqrt{x^2} = x.\]

The general rule is this: to find out whether a function has an inverse, look at its domain and its range, and then figure out whether for every element \(y\) in the range there is exactly one element \(x\) in the domain so that \(f(x)=y\). If there is, then you can go backwards.