Is there a "non-trivial" function $f(x,y)$ such that
$$f(x,y) \in \mathbb{Q} \iff x,y\in \mathbb{Q}?$$
An example of a "trivial" function would be
$$f(x,y) = \begin{cases} 0 & x,y\in \mathbb{Q}\\ \pi & \text{otherwise} \end{cases}$$ or any other $f$ which effectively uses a cases function.
The motivation is just my curiosity. Obviously, operations which preserve one direction of the $\iff$ are plentiful and well-studied. I was wondering how onerous the condition of the additional direction is on the choice of $f$. This question on mathoverflow seems related.