Can there be two distinct, continuous functions that are equal at all rationals?
Akhil showed that the Cardinality of set of real continuous functions is the same as the continuum, using as a step the observation that continuous functions that agree at rational points must agree everywhere, since the rationals are dense in the reals.
This isn't an obvious step, so why is it true?
Solution 1:
Without resorting to ε-δ arguments: Let $f$ and $g$ be continuous real functions and $f(x) = g(x)$ for all rational $x$. For any real number $c$ (in particular, an irrational $c$), there exists a Cauchy sequence of rational numbers such that $\lim_{n \to \infty}x_{n}=c$. Since $f$ and $g$ are continuous, $\lim_{n \to \infty}f({x_{n}})=f({c})$ and $\lim_{n \to \infty}g({x_{n}})=g({c})$. Since $x_n$ is rational, $f(x_n) = g(x_n)$ for all $n$, so the two limits must be equal and so $f(c) = g(c)$ for all real $c$.
Solution 2:
And one more proof, using the topological notion of continuity: Suppose for contradiction that there exists some $x$ with $f(x)-g(x) = k \neq 0$. Without loss of generality, we can take $k > 0$. Since $f$ and $g$ are continuous, $f-g$ is continuous, so we must have that $f(x) - g(x) > 0$ on a non-empty open set $S$ since the inverse image of the open interval $(k/2, 3k/2)$ must be open. But since the rationals are dense in the reals, $S$ must contain a rational number $y$, with $f(y) \neq g(y)$, a contradiction.
Solution 3:
If there were two continuous functions $f(x)$ and $g(x)$ that were equal at all rationals, then (because the rationals are dense) we can show that $\lim_{x \to a} f(x) - g(x) = 0$ for all values of $a$ using a delta-epsilon proof.
Since the difference of two continuous functions is continuous, we know $\lim_{x \to a} f(x) - g(x) = f(a) - g(a)$ for all $a$, and therefore $f(a) - g(a) = 0$ and $f(x) = g(x)$, proving that $f$ and $g$ must be identical.
Solution 4:
Sketch of an alternative proof.
First, recall (or see for the first time) the following fact:
Given a continuous function $h: \mathbb{R} \rightarrow \mathbb{R}$, the set $K_h := \{x \in \mathbb{R}: h(x) = 0\}$ is closed.
"Recalling" this fact might seem just like sweeping details under the rug; indeed, it is Exercise $4.3.7$ in Stephen Abbott's introductory textbook Understanding Analysis.
Nevertheless, one can then proceed as follows:
Let $f, g: \mathbb{R} \rightarrow \mathbb{R}$ be continuous, real-valued functions that agree on $\mathbb{Q}$.
Furthermore, let $h = f - g$. Then $h$ is the difference of continuous functions, hence continuous itself; we can now use the fact above to conclude that $\mathbb{Q} \subset K_h \subset \mathbb{R}$.
In particular, $K_h$ is a closed set of real numbers that contains $\mathbb{Q}$.
We are given that the rationals are dense in the reals, i.e., $cl(\mathbb{Q}) = \mathbb{R}$.
Therefore, $K_h = \mathbb{R}$, which means that for all $x \in \mathbb{R}$, we have $h(x) = 0$.
By the definition of $h$, this means for all $x \in \mathbb{R}$ we have $f(x) - g(x) = 0$, i.e., $f(x) = g(x)$.
This "proves" the desired result. QED
N.B. The problem posed here is also in Abbott's text: it is Exercise $4.3.8(b)$.