Let X and Y be metric spaces and let f be a
function from X to Y such that f^{-1}(U) is open for
every open subset U of Y. Then f is continuous.

1. The conclusion we want is

(for all a > 0) (for all x in X) (there exists b> 0) (for all y in X) d(x,y) < b implies d(f(x),f(y)) < a.

2. Applying the for-all-removing move, we write

* Let * a > 0 * and let * x *
be an element of * X.

The conclusion we want now becomes

(i) (there exists b> 0) (for all y in X) d(x,y) < b implies d(f(x),f(y)) < a.

3. As a general rule, the difficulty, such as it is, of an easy analysis problem arises when one is faced with a statement to be proved that begins with "there exists", since one must do some work to find something. At the moment we have nothing to go on, so now is the time to write out our hypothesis in full.

(for all U) U is an open subset of Y implies
that f^{-1}(U) is an open subset of X.

4. This tells us that if we are to make progress then we must come up with an open set. Notice that this is a sort of "dual" situation to what we have already had. If "for all" appears in a hypothesis, then we need to find something. So does this mean we are stuck? Not yet, because there is another general technique which is very useful in exactly this sort of situation. It is to pretend to ourselves that we have chosen U, and then see what properties of this putative set we need to get the rest of the proof to work. So let us write the following line (which, once we have decided on a U, we can go back and erase):

* Let * U * be an open subset of
* Y * to be determined later. *

5. We are now in a position to use our hypothesis. It immediately allows us to write the following line.

* Then * f^{-1}(U) * is
open. *

6. Expanding out the definition of "open" gives us

* In other words * (for all z in
f^{-1}(U)) (there exists c > 0) (for all w in X)
d(z,w) < c implies w is in f^{-1}(U).

7. This still doesn't obviously match up with (i) (or
rather it does, but not yet obviously enough for a very basic
algorithm to realize). So let's expand out the definition of
f^{-1} (twice).

(ii) (for all z in X) [f(z) is in U] implies [(there exists c > 0) (for all w in X) d(z,w) < c implies f(w) is in U].

8. We are now in a position to get matching. For convenience here is (i) again.

(i) (there exists b> 0) (for all y in X) d(x,y) < b implies d(f(x),f(y)) < a.

In (ii) we would like to choose a value for z and choose letters for the bound variables c and w in order to get as close as possible to (i). The most promising potential match we have is between "d(x,y) < b" in (i) and "d(z,w) < c" in (ii). Bearing in mind that x is fixed and y is a bound variable, there is exactly one way of making the choice to match these two statements, so let us specialize (ii) to the case z=x and rewrite c and w as b and y respectively, obtaining

(ii)' (there exists b > 0) (for all y in X) d(x,y) < b implies f(y) is in U.

For the specialization to x to be valid, we need f(x) to belong to U, so let us bear that in mind as a property that U will have to have when we choose it.

9. Statements (i) and (ii)' look very similar now. Indeed, all that we are required to do is to come up with an open set U such that f(x) is in U (for the reason I have just given) and such that [f(y) is in U] implies [d(f(x),f(y)) < a].

10. Well, it may seem blindingly obvious what to choose for U, but let's try to come up with it without relying on our prior knowledge that open balls are open.

One way to do this is to try to rewrite the statement [d(f(x),f(y)) < a] in such a way that it matches more closely the statement [f(y) is in U]. For example, can we get it to begin with "f(y) is in"? Yes, in the following artificial way: f(y) is in {z:d(f(x),z) < a}. This has the advantage of generating a set. We need to find an open subset of it that contains f(x).

11. The most obvious two subsets of it are the empty set and the set itself. The empty set clearly doesn't work, so the next simplest thing to try is the set itself. Does it contain f(x) and is it open?

12. It is trivial to check that {z:d(f(x),z) < a} contains f(x). To check that it is open is less trivial, but counts as a decidedly simpler problem than the one we started with, so I will not give the details of how to prove this on autopilot. (Perhaps some time I will do it on a different page and then provide a link.) So, assuming these details, the proof is discovered.