# "Least trivial" function preserving rationality

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.

• Well, you definitely can't have a continuous function satisfy this. If any two values of $f$ differ, you can come up with uncountably many paths between them (e.g. $(x,Cx(1-x))$ parameterizes in $C$ such a family of paths from $(0,0)$ to $(1,0)$) and then choose some rational $r$ between their values, and the intermediate value theorem says that $f(x,y)=r$ has uncountably many solutions - but $\mathbb Q\times\mathbb Q$ is countable, so that's not good. More strongly, $f$ may not be continuous on any open set. Jun 1, 2015 at 2:53

Perhaps a slightly less trivial example would be the function $f$ that interleaves the decimal digits of $x$ and $y$: that is, if \begin{align} x&=0.x_1x_2x_3\dots \\ y&=0.y_1y_2y_3\dots \end{align} are decimal expansions of $x$ and $y$, then $$f(x,y)=0.x_1y_1x_2y_2x_3y_3\dots$$

You can make this definition unambiguous by deciding to always (or never) take finite decimal expansions when they are available.

Then $f(x,y)$ has a repeating decimal expansion if and only if both $x$ and $y$ do, and so it satisfies your condition.

• This is a really good answer. One might be tempted to use arithmetic operations for this but the irrationals are not closed under the standard arithmetic operations so that approach isn't very fruitful. Very nice insight! Jun 1, 2015 at 2:30
• Similarly, interleaving the continued fraction expansions of $x$ and $y$ preserves rationality, since a real number is rational if and only if its continued fraction terminates. Jun 1, 2015 at 2:51
• This is even continuous at points where neither $x$ nor $y$ has a terminating decimal! Jun 1, 2015 at 2:57
• @Hugh: Yes, this follows from Meelo's comment. The set of discontinuities is a subset of $(\mathbb Q \times \mathbb R) \cup (\mathbb R \times \mathbb Q)$, which has measure zero. Jun 1, 2015 at 15:05
• The usual problem with this interlace scheme (that it is not onto) is not a problem here, because that is not required in the problem. Jun 1, 2015 at 15:54

This is an interesting question.

The answer would depend on how the functions are defined. My inclination is to say that the answer is "no", because irrationals can be made to cancel out to give a rational.

However, if limiting processes can be used, perhaps a function that uses the fact that rationals can not be well-approximated by rationals (error in approximation by $a/b$ at best $\Omega(1/b)$) and irrationals can (error in approximation by $a/b$ at worst $O(1/b^2)$) could be constructed.

• Of course, limiting processes can result in cases functions like that in the OP's example. Jun 1, 2015 at 2:32

I think the function f must be understood to be from $\mathbb{R}^2$ to $\mathbb{R}$ so I choose • This is "trivial".
– Hugh
Jun 3, 2015 at 2:33