To find continuous functions on $\mathbb R$ which preserve certain algebraic structures 
Can we determine all non-constant continuous functions $f:\mathbb R \to \mathbb R$ such that for every subgroup $G$ of $(\mathbb R,+)$, $f(G)$ is also a subgroup of $(\mathbb R,+) $ ? 

And similarly, 

characterize all continuous functions on $\mathbb R$ which preserves subrings and also those which preserves $\mathbb Q$-vector subspaces of $\mathbb R$ ?

 A: There are a large number of continuous functions $\mathbb{R}\to\mathbb{R}$ that map $\mathbb{Q}$-vector subspaces to $\mathbb{Q}$-vector subspaces.  To illustrate this, I will prove the following theorem:
Theorem. There exists a continuous function $f\colon\mathbb{R}\to\mathbb{R}$ with the property that
$$
f(V) = V+\mathbb{Q}
$$
for every nonzero $\mathbb{Q}$-vector subspace $V\subset \mathbb{R}$.
The function $f$ I'm going to construct is piecewise-linear, where each linear piece has the form
$$
f(x) = ax+b
$$
for some $a,b\in\mathbb{Q}$.  We shall refer to such functions as rational piecewise linear.  Note that a rational piecewise linear function automatically satisfies $f(V) \subset V+\mathbb{Q}$ for any subspace $V$, so we only need to worry about $f$ mapping each $V$ onto $V+\mathbb{Q}$.
To construct the function $f$, we start by making a list of requirements for $f$. Here a requirement is a statement of the form

For every nonzero $\mathbb{Q}$-vector subspace $V$, the image $f(V)$ contains $(q+V)\cap [a,b]$,

where $q$ is a rational number, $[a,b]$ is a closed interval with rational endpoints, and either $q\notin [a,b]$ or $q=a=b$.  We shall denote such a requirement $R(q,[a,b])$.  Note that it suffices to show that $f$ passes all such requirements.
We need to talk about $f$ passing a requirement on a given domain interval.  If $[c,d]$ is an interval in the domain and $R(q,[a,b])$ is a requirement, we say that $f$ passes $R(q,[a,b])$ on $[c,d]$ if $f(V\cap[c,d]) \supset (q+V)\cap[a,b]$.
The main technical lemma is the following.
Lemma. Let $c \geq 0$ and $c'$ be rational numbers, and let $R(q,[a,b])$ be a requirement.  Then there exists a rational number $d>c$ and a rational piecewise linear function $g\colon [c,d] \to \mathbb{R}$ so that $g(c)=c'$ and $g$ passes $R(q,[a,b])$ on $[c,d]$.
Here's how we plan to use the Lemma.  Note that there are only countably many requirements, so we can enumerate them $R_1,R_2,R_3,\ldots$.  Then we will construct a rational piecewise linear function $f$ so that


*

*$f(0)=0$,

*$f$ passes $R_1$ on some interval $[0,a_1]$,

*$f$ passes $R_2$ on some interval $[a_1,a_2]$,

*and so forth.
In each case, the definition of $f$ on $[a_n,a_{n+1}]$ is a function $g\colon[a_n,a_{n+1}]\to\mathbb{R}$ obtained using the Lemma, and we make sure that $f$ is continuous by insisting that $g(a_n)$ is equal to the previously defined value of $f(a_n)$.  Then $f$ will pass all the requirements on $[0,\infty)$, so we can just let $f$ be the identity function on $(-\infty,0)$ and we will be done.
All that remains is to prove the Lemma.
Proof of the Lemma: We are given rational numbers $c,c'$ where $c\geq 0$ and a requirement $R(q,[a,b])$, and we wish to construct a function $g$.  There are two cases:


*

*If $q=a=b$, let $g$ be the rational piecewise linear function whose graph goes from $(c,c')$ to $(c+1,q)$ to $(c+2,q)$.  Then for any nonzero $\mathbb{Q}$-linear subspace $V\subset\mathbb{R}$, there must be some element $v\in V$ in the interval $[c+1,c+2]$, so $g(v)=q$.  Then
$$
g(V\cap[c,c+2]) \supset \{q\} = (q+V) \cap [q,q]
$$
so $g$ satisfies $R(q,[q,q])$ on $[c,c+2]$.

*Suppose $q\notin [a,b]$.  Then either $q<a$ or $q>b$, so without loss of generality suppose that $q<a$.  Let $r>0$ be a rational number small enough so that the line $y=rx+q$ intersects the line $y=a$ at some $x$-value $\gamma > c$. Let $\delta$ be the $x$-value at which the line $y=rx+q$ intersects the line $y=b$, and let $g$ be the rational piecewise linear function whose graph goes from $(c,c')$ to $(\gamma,a)$ and then follows the line $y=rx+q$ from $(\gamma,a)$ to $(\delta,b)$, as shown in the following figure.

We claim that $g$ satisfies $R(q,[a,b])$ on $[c,\delta]$.
Let $V\subset\mathbb{R}$ be a nonzero $\mathbb{Q}$-linear subspace.  Then any element of $(q+V)\cap[a,b]$ can be written as $q+v$ for some $v\in V$. Then the line $y=rx+q$ intersects $y=q+v$ at the point $(v/r,v+q)$.  Clearly $v/r$ lies in the interval $[\gamma,\delta]$, and hence $g(v/r) = v+q$.  But $r\in\mathbb{Q}$, so $v/r\in V$, which proves that $g(V\cap[c,\delta])\supset (q+V)\cap[a,b]$.$\quad\square$
This finishes the proof.  I suspect that there are a large number of functions mapping subgroups to subgroups and subrings to subrings as well, but I don't have a proof for those cases.
