TITLE: Periodic function $f$ for which $f(x^2)$ is periodic too
QUESTION [10 upvotes]: There is the following question which was asked multiple times on Math.SE (e.g. here and here) without any final result:

Question: Is there a periodic function $f:\Bbb R \to\Bbb R$ of smallest period $1$, for which $g(x):=f(x^2)$ is periodic too (of period $\alpha$)?

We know that no  such function can be continuous. The best approach so far was to define an equivalence relation $\sim$ on $\Bbb R$ via
$$x\sim x\pm 1\qquad\text{and}\qquad x^2\sim (x+\alpha)^2.$$
The function $f$ defined by 
$$f=\begin{cases}
0 &\text{for } x\sim0 \\
1 &\text{for } x\not\sim0
\end{cases}$$
is then periodic (of period $1$) and $g(x):=f(x^2)$ is periodic too (of period $\alpha$). But how to prove (if true) that $1$ is the smallest period of $f$? Another observation is that any other possible period $\lambda\in(0,1)$ of $f$ must satisfy $\lambda\sim 0$ since
$$f(\lambda)=f(0)=0\quad\Rightarrow\quad \lambda\sim 0.$$

REPLY [7 votes]: Here is a proof that Ilya's example works.
Fix a positive real transcendental $\alpha$ and define the functions $f_n:x\mapsto x+n$ and $g_n:x\mapsto(\sqrt{x}+n\alpha)^2$ for integer $n$, which generate the equivalence relation $\sim$. 
Fix a real $r$ (Ilya's $a$) that is algebraically independent of $\alpha$ over $\mathbb{Q}$. Suppose $r+\beta\sim r$ for some $\beta\in\overline{\mathbb{Q}(\alpha)}$. Then there's a witness sequence of (WLOG nonzero) integers $n_i$ and $m_j$ such that $(f_{n_1}\circ g_{m_1}\circ\cdots f_{n_k}\circ g_{m_k}\circ f_{n_{k+1}})(r)=r+\beta$. By the algebraic independence of $r$, this equation holds identically for all real $r$. Therefore it remains true after taking the derivative with respect to $r$ and setting $r$ to be a rational number. It then becomes $(g'_{m_1}\circ\cdots f_{n_k}\circ g_{m_k}\circ f_{n_{k+1}})(r)\cdot (g'_{m_2}\circ\cdots f_{n_k}\circ g_{m_k}\circ f_{n_{k+1}})(r)\cdots(g'_{m_k}\circ f_{n_{k+1}})(r)=1$, since $f'_n=1$. This can be written as an algebraic equation with rational coefficients solved by $\alpha$, so it is true regardless of $\alpha$'s value. As it turns out, if $k>0$ then the left hand side diverges as $\alpha\to\infty$.
To wit, for fixed $r$ and as $\alpha\to\infty$, $f_{n_{k+1}}(r)$ stays constant, while $(f_{n_k}\circ g_{m_k}\circ f_{n_{k+1}})(r)=\Theta(\alpha^2)$, $(f_{n_{k-1}}\circ g_{m_{k-1}}\circ f_{n_k}\circ g_{m_k}\circ f_{n_{k+1}})(r)=\Theta(\alpha^2)$, and so on. Therefore $(g'_{m_k}\circ f_{n_{k+1}})(r)=\Theta(\alpha)$ yet every earlier term in the chain rule product (e.g. $(g'_{m_{k-1}}\circ f_{n_k}\circ g_{m_k}\circ f_{n_{k+1}})(r)$) is $\Theta(1)$. Hence there are no $g$ terms in the witness of $r+\beta\sim r$, which means that $\beta\in\mathbb{Z}$.