Background:
I'm reading on book on Real analysis by Carothers where the author first shows that the map $x \mapsto d(x, A)$ is continuous (in fact, 1-Lipschitz), and then argues the following:
To appreciate what this has done for us, let’s make two simple observations. First, if $f : M \to \mathbb{R}$ is a continuous function, then the set $E = \{ x \in M : f(x) = 0 \}$ is closed. Conversely, if $E$ is a closed set in $M$, then $E$ is the “zero set” of some continuous real-valued function on $M$; in particular, $E = \{ x \in M : d(x, E) = 0 \}$. Thus a set $E$ is closed if and only if $E = f^{-1}(\{0\})$ for some continuous function $f : M \to \mathbb{R}$.
Conclusion: If you know all of the closed (or open) sets in a metric space $M$, then you know all of the continuous real-valued functions on $M$ (Theorem 5.1). Conversely, if you know all of the continuous real-valued functions on $M$, then you know all of the closed (or open) sets in $M$.
Theorem 5.1 states (in particular) that a function is continuous by the $\epsilon$-$\delta$ definition if and only if the preimage of every closed set is closed.
My question:
Now in the first paragraph, nothing is unclear to me but the first statement in the second paragraph is: I fail to understand why knowing all the closed sets lets one know all the continuous real-valued functions? Or at least, how can one reason this without using sequences (see below).
What I've tried:
The second statement (of the second paragraph) is clear to me: given a set, if one knows all the ways it can be mapped continuously, then one knows if the set can be mapped continuously to $\{0\}$ or not, i.e., if the set is closed or not by the remarks of the first paragraph.
But the first statement eludes me; after some time, I came to the conclusion (or dead end) that the logic behind it is that, given a function $f: M \to \mathbb{R}$, if one knows all the closed sets of $M$, one knows if the preimage (under $f$) of some closed set of $\mathbb{R}$ is not closed. But what bothers me here is that this logic requires one to know all the closed sets of $\mathbb{R}$ as well.
Is there something here that I'm missing or is it supposed to be just "obviously given" that one knows all the closed sets of $\mathbb{R}$?
However, I found a way how to circumvent this logic by using open sets and sequences: if we know all the closed sets, we know all the open sets as well, and hence, given a sequence, we know if some point is such that all the open sets that contain the point are eventually supersets of given sequence. That is, we know all the convergent sequences and their limits. And now we know if there exists an $x$ such that there exists a sequence $x_n \to x$ such that $f(x_n) \not\to f(x)$, i.e., we know whether $f$ is continuous.
But this seems to be a bit roundabout way of doing it, and it bothers me tremendously that I can't see the direct way of doing it. And, having searched through this site, and as far as I understand the stuff in this post, one can't even use this sequence-based reasoning in general topological spaces as they are not necessarily sequential.