$g(x) = g(y)$ iff $x$ and $y$ differ by a rational number I’m looking for a function $g$ on the real numbers such that $$g(x) = g(y) \iff x - y \in \mathbf{Q}.$$
Any ideas? I wish that I could share some progress, but I’ve had a hard time even getting started. My first attempt was the simple function
$$g(x) = \begin{cases} x & x \text{ irrational,} \\ 0 & x \text{ rational.}\end{cases}$$
But this won’t work: $g(\sqrt{2} + 1/2) \neq g(\sqrt{2})$.
 A: If you just want the domain to be the real numbers, that's easy. $g(x)=\{y\in\Bbb R\mid x-y\in\Bbb Q\}$ is exactly the function you're looking for.
If you want a function into the real numbers, that's not possible without utilising the axiom of choice. Suppose that it was, namely, that $\sf ZF$ proves that there exists a function $g\colon\Bbb{R\to R}$ such that $g(x)=g(y)\iff x-y\in\Bbb Q$. Then this function would induce $f\colon\Bbb{R/Q\to R}$ given by $f([r]_\Bbb Q)=g(r)$, and this $f$ will be injective. Because if $[r]_\Bbb Q\neq[r']_\Bbb Q$, then $r-r'\notin\Bbb Q$ and therefore $g(r)\neq g(r')$.
Alas, it is consistent with $\sf ZF$ that there is no injective function $f\colon\Bbb{R/Q\to R}$. For example, in Solovay's model, where every set of reals is Lebesgue measurable.
So there is no chance of just defining a function like this "by hand". All we can do is appeal to the axiom of choice, and use the fact that $\Bbb{R/Q}$ is a family of non-empty sets, and therefore there exists $f$ such that $f([r]_\Bbb Q)\in [r]_\Bbb Q$ for all $r\in\Bbb R$.
