To find all functions $f: \mathbb R \rightarrow \mathbb R$ such that Such that for all $x,y \in \mathbb R$ we have that $x-y \in \mathbb Q \implies f(x) - f(y) \in \mathbb Q$.
I noticed that $x-y \in \mathbb Q \implies f^n(x) - f^n(y) \in \mathbb Q$ ($f^2(x) = f(f(x))$ and not $f(x) \cdot f(x)$).
I also tried to partition $\mathbb R = A \cup B$ where $A = \{x, f(x) \in \mathbb Q\}$ and $B = \{x, f(x) \in \mathbb R-\mathbb Q\}$ and to analyze: when $f(0)$ is rational and when it isn't.
If $0 \in B$ then $\mathbb Q \in B$. My problem is to verify $f$ of irrational numbers. Thank you all in advance.
 A: Here's a group theoretic approach. Let $S$ be the set of functions $f : \mathbb{R} \to \mathbb{R}$ such that $x-y \in \mathbb{Q} \implies f(x) - f(y) \in \mathbb{Q}$. $S$ is an abelian group under pointwise addition. Let $A$ be the set of functions (not neccesarily group homomorphisms) $\mathbb{R}/\mathbb{Q} \to \mathbb{R}/\mathbb{Q}$, where $\mathbb{R}/\mathbb{Q}$ is the quotient group. $A$ is also an abelian group under pointwise addition.
There is a function $F : S \to A$ defined by $F(f)([x]) = [f(x)]$. $F$ is a group homomorphism, and we will prove that $F$ is surjective. By the axiom of choice, let $\iota : \mathbb{R}/\mathbb{Q} \to \mathbb{R}$ be a section of the canonical projection $\pi : \mathbb{R} \to \mathbb{R}/\mathbb{Q}$. This gives a map $I := \varphi \mapsto \iota \circ \varphi \circ \pi : A \to S$, which is a section of $F$ since
$$F(I(\varphi)) \circ \pi = \pi \circ I(\varphi) = \pi \circ \iota \circ \varphi \circ \pi = \varphi \circ \pi$$
and $\pi$ is surjective. By the first isomorphism theorem, there exists a bijection $A \times \ker F \to S$, so we should seek to understand $\ker F$.
If $f \in \ker F$, we have that for all $x \in \mathbb{R}$, $[f(x)] = F(f)([x]) = [0] = \mathbb{Q}$, so $f(x) \in \mathbb{Q}$. Conversely, if $f : \mathbb{R} \to \mathbb{Q}$, then $f \in \ker F$ (technically, it's the corestriction of $f$ that's in the kernel). We conclude that $\ker F$ is (in bijection with) the set of functions $\mathbb{R} \to \mathbb{Q}$.
This makes $\ker F$ an injective abelian group, so $S \cong \ker F \times A$ as abelian groups. The isomorphism is given by $f \mapsto (\ell(f), F(f)) : S \to \ker F \times A$ where $\ell : S \to \ker F$ is a homomorphic section of the inclusion $\ker F \to S$. However, I don't know how to pick $\ell$ without some kind of choice (or well-ordering, etc.). In any case, we can tell that $$\lvert{S}\rvert = \lvert \ker F \rvert \times \lvert A \rvert = \aleph_0^{\lvert \mathbb{R} \rvert} \cdot \lvert \mathbb{R} \rvert^{\lvert \mathbb{R} \rvert} = \lvert \mathbb{R} \rvert^{\lvert \mathbb{R} \rvert} = 2^{\lvert\mathbb{R}\rvert},$$
so there are many such functions.
A: Take an arbitrary function
$$f:\mathbb{R}\rightarrow\mathbb{R}$$
Now let's consider the equivalence relation
$$x\sim y \ \Leftrightarrow x-y\in\mathbb{Q}$$
Now, you want that, $\forall x, \ y\in\mathbb{R} \ \mid x-y\in\mathbb{Q}$, $f(x)-f(y)\in\mathbb{Q}$.
Let's take
$$\pi:f(\mathbb{R})\rightarrow f(\mathbb{R})/\sim$$
Now it's easy.
Let 
$$X=\lbrace f:\mathbb{R}\rightarrow\mathbb{R}\mid \pi(f(x)) = \pi(f(y)), \ \forall x, \ y \ such \ that \ x-y\in\mathbb{Q}\rbrace$$
Now you can see it better.
