# $f(a)-f(b)$ is rational iff $f(a-b)$ is rational

Prove that the continuous function $$f:\mathbb{R} \to \mathbb{R}$$ satisfying $$f\left(x\right)-f\left(y\right) \in\mathbb{Q} \iff f\left(x-y\right) \in \mathbb{Q}$$ is of the form $$f\left(x\right)=ax+b.$$

My Attempt.

I tried considering the function $$g\left(x\right)=\frac{f\left(x\right)-f\left(0\right)}{f\left(1\right)-f\left(0\right)}$$ which also satisfies the property $$g\left(a\right)-g\left(b\right) \in\mathbb{Q} \iff g\left(a-b\right) \in \mathbb{Q}$$,

Now I am trying to prove that this function g is identity function and then I can prove that $$f\left(x\right)=\left(f\left(1\right)-f\left(0\right)\right)x+f\left(0\right).$$ And I am done.

Also This function has to be identity function because $$g\left(0\right)=0$$ and $$g\left(1\right)=1$$.

I tried assuming that the function g is such that $$g\left(a\right)\neq a$$ for some $$a\in \mathbb{R}$$. Then by continuity $$g\left(x\right)\neq x$$ for some $$\delta>0$$ neighborhood of $$a$$. But I cannot move further.

Also Using a previously known result, I was able to prove that f must be monotonic. However I do not want to use any other result which is not known and not trivial.

If a function $$f$$ is continous in $$\left[a,b\right]$$ and $$f\left(a\right)=f\left(b\right)$$ then for any $$\epsilon >0$$ there exists $$m,n \in \left[a,b\right]$$such that $$f\left(m\right)=f\left(n\right)$$ and $$m-n=\epsilon$$.

In this case choose $$\epsilon \in \mathbb{R}-\mathbb{Q}$$ and get $$m,n \in \left[a,b\right]$$ such that $$f\left(m\right)-f\left(n\right)=0 \in \mathbb{Q}$$ but $$m-n \in\mathbb{R}-\mathbb{Q}$$.

For any $$y$$, we have either $$f(x+y) - f(x) \in \mathbb Q$$ for all $$x$$, or $$f(x+y) - f(x) \notin \mathbb Q$$ for all $$x$$, depending on whether or not $$f(y) \in \mathbb Q$$. But $$f(x+y)-f(x)$$ is continuous, so by the Intermediate Value Theorem we conclude $$f(x+y) - f(x)$$ is constant. Thus $$f(x+y) - f(x) = f(y) - f(0)$$ This says $$f(x) - f(0)$$ is an additive function. And it's not hard to prove that continuous additive functions are linear.