# Why is every continuous function on the reals determined by its value on rationals? [closed]

Why is every continuous function on the reals determined by its values on the rationals?

• is this homework? what is the context? what did you try? May 3, 2013 at 3:03
• In fact, it's enough to know the values on the set $\{\frac{a}{p}:a\in \mathbb{Z}, p\textrm{ prime}\}$. May 3, 2013 at 3:12
• @vadim123 or any dense set in reals?
– mez
Jun 1, 2013 at 13:20
• Jul 29, 2021 at 12:41

Since the rationals are dense in the reals, we can construct a sequence $(q_n)_1^\infty$ of rational numbers approaching any real number $x \in \mathbb{R}$.

Since $f$ is continuous, we know that can achieve the second equality in the statement below (we can pass limits under application of continuous functions): $$f(x) = f\left( \lim_{n \to \infty} q_n \right) = \lim_{n \to \infty} f(q_n).$$

The expression on the right hand side is only in terms of the value of the function at rational numbers. Thus, since we know what a continuous function $f$ does with rational numbers that are arbitrarily close to a real number $x$, we know what it will map that real number $x$ to.

• LoL you beat me to it. May 3, 2013 at 3:20

Since the rationals are dense in $\mathbb{R}$.

If we choose a $x_i \in \mathbb{Q}^{\mathcal{c}}$, we can construct a sequence of rational numbers $(x_n)_{n\in\mathbb{N}}$ such that $\lim_{n\to\infty}x_n = x_i$.

Recall, a characterization of continuity is that $\lim_{x\to x_0} f(x) = f(x_0)$. Hence,

$$\lim_{n\to\infty}f(x_n) = f(x_i)$$

So, if we know $f|_{\mathbb{Q}}$, we actually can extend this to $f$.

Suppose I have two continuous functions $f,g:\mathbb{R}\to\mathbb{R}$ that agree at every rational number. You want to conclude that $f(x)=g(x)$ for every real number $x$. Alternatively, you can show that $f(x)-g(x)=0$ for every real number $x$.

$f-g$ is a continuous function on $\mathbb{R}$, and $(f-g)(q)=0$ for every rational number $q$. Let $x$ be an arbitrary real number. Since the rationals are dense in the reals, we choose a sequence of rational numbers converging to $x$. On this sequence $f-g$ is identically zero, and passing to the limit by continuity, we conclude that $(f-g)(x)=0$. Since $x$ was arbitrary $f-g$ is identically zero on $\mathbb{R}$. So a continuous function on $\mathbb{R}$ is uniquely determined by its values on $\mathbb{Q}$.

Hint: You need to use the property of continuous functions that says continuous functions map convergent sequences to convergent sequences, that is if $f$ is continuous and $x_n \to a$, then $f(x_n) \to f(a)$. The other fact you need is that if $a$ is irrational, then there exists a Cauchy sequence of rational numbers such that $x_n \to_{n\to \infty} a$.