Prove if $f(x) = g(x)$ for each rational number x and $f$ and $g$ are continuous, then $f = g$ [duplicate]

$f,g: \mathbb{R} \to \mathbb{R}$

I'd like to see a sketch for this proof.

[sorry for posting errors, I am on a cell phone]


Solution 1:

Suppose $h(x) = f(x) - g(x)$. Then $h(x)$ is continuous and $h(x) = 0$ if $x \in \mathbb{Q}$. Let $\alpha$ be irrational. If $h(\alpha) > 0$ then since it is continuous there is a neighborhood $I$ of $\alpha$ in which $h(x)$ is positive. Clearly this neighborhood also includes rational numbers at which $h(x) = 0$. This contradiction shows that we can't have $h(\alpha) > 0$. Similarly we can't have $h(\alpha) < 0$. Thus $h(\alpha) = 0$. So $h(x) = 0$ for all $x$.

Solution 2:

Hint. For every real number $r$ there is a rational sequence $(q_n)$ such that $q_n\to r$ as $n\to\infty$. You can check that $f(q_n)=g(q_n)$ for all $n$. Take $n\to\infty$.

Solution 3:

Different hint: Suppose there's an irrational $a$ such that $f(a) \neq g(a)$. Can they still be continuous at that point?