# Dense subset of $C[0,1]$ which preserves rationals

I am trying to prove the following:

In $$C[0,1]$$ the functions that preserve the rationals (i.e. $$f(\mathbb{Q})\subseteq \mathbb{Q}$$) are dense.

So far, I have not made much progress- I am aware that $$A$$ is dense in $$B$$ iff $$A$$ has non-empty intersection with each open set $$U$$ in $$B$$ but am not sure how to apply this definition. I have also thought about showing that the closure of $$X$$ (where $$X$$ is the set of functions that preserve the rationals) is equal to $$C[0,1]$$ by a double-inclusion proof but I have also made no progress with this approach. Am I on the right track or should I change my approach?

• Polynomials with rational coefficients are dense. Sep 29, 2020 at 11:42
• @KaviRamaMurthy is it the case that the only continuous functions which preserve the rationals are polynomials with rational coefficients? Sep 29, 2020 at 12:54
• $1/(1+x)$ is not a polynomial. Sep 29, 2020 at 13:09
• Ok, so I'm guessing that the only continuous functions which preserve rationals are functions of the form $f(x)= \frac{p(x)}{q(x)}$ where p and q are polynomials with rational coefficients. Is there a way of proving this is the case? @KaviRamaMurthy Sep 29, 2020 at 14:31

Without the Weierstrass Theorem: Given $$f\in C[0,1]$$ and $$r>0$$ we can find $$g\in C[0,1]$$ with $$g[\Bbb Q\cap [0,1]]\subset \Bbb Q$$ and $$\sup \{|g(x)-f(x)|: x\in [0,1]\}\le r$$ as follows:

$$f$$ is uniformly continuous.

Let $$s>0.$$ Take $$n\in \Bbb N$$ such that $$|f(x)-f(y)| whenever $$|x-y|\le 1/n.$$

For integer $$j$$ with $$0\le j\le n,$$ take $$g(j/n)\in \Bbb Q$$ with $$|g(j/n)-f(j/n)| For integer $$j$$ with $$0\le j\le n-1,$$ let $$g$$ be linear on the interval $$[j/n,(j+1)/n].$$

For any $$x\in [0,1]$$ take integer $$j\le n-1$$ such that $$x\in [j/n, (j+1)/n].$$ We have $$|g(x)-g(j/n)|\le |g((j+1)/n))-g(j/n)|<3s$$ because $$|g((j+1)/n)-f((j+1)/n)| and $$|g(j/n)-f(j/n)| and $$|f((j+1)/n)-f(j/n)| We have $$|g(j/n)-f(x)|< 2s$$ because $$|g(j/n)-f(j/n)| and $$|f(j/n)-f(x)| Therefore $$|g(x)-f(x)|<5s.$$ Now if $$s=r/5$$ we have $$|g(x)-f(x)| for all $$x\in [0,1].$$

By the Weierstrass approximation theorem we get that polynomials with real coefficients are dense in $$C[0,1]$$.

On the other hand polynomials with rational coefficients are dense in polynomials with real coefficients (simply by per-coefficient approximation).

Finally a polynomial with rational coefficients maps rationals to rationals. And so we get even stronger result:

Polynomials with rational coefficients are dense in $$C[0,1]$$.

• Thanks. In order to complete the proof would I not also need to show that the set of continuous functions that are not polynomials with rational coefficients but still preserve the rationals (e.g $f(x)=\frac{1}{1+x}$) are also dense in $C[0,1]$? Sep 29, 2020 at 16:06
• @stokes indeed. But every superset of a dense subset is dense as well. Regardless of topology. Sep 29, 2020 at 18:01
• Of course! Thank you @freakish Sep 30, 2020 at 10:16
• @stokes I added an answer to your question about continuous functions that are not polynomials with rational coefficients but still preserve the rationals. They are in fact dense.
– zhw.
Sep 30, 2020 at 15:14

Just to take up a problem suggested by the OP in a comment: Let $$D$$ be the set of continuous functions that are not polynomials with rational coefficients, but sill send rationals to rationals. Then $$D$$ is dense in $$C[0,1].$$ Proof: Let $$f\in C[0,1]$$ and $$p$$ a polynomial with rational coefficients. Let $$n$$ be the degree of $$p.$$ Then for $$m=1,2,\dots,$$ the functions

$$q_m(x) = \frac{p(x)}{(1+x/m)^{n+1}}$$

are not polynomials, but do take rationals to rationals. You can verify that $$q_m\to p$$ uniformly on $$[0,1]$$ as $$m\to \infty.$$ Since $$|p-f|$$ can be as small as we want (Weierstrass), the result follows.