Constructing a function $f : \Bbb R^2 \to \Bbb R$ such that $f(a, b)$ is an integer if and only if $a, b$ are integers. 
What are some examples of functions $f(a,b)$ that is an integer if and only if when $a$ and $b$ are both integers? We require that $f$ be continuous, though not necessarily differentiable, and that we only use elementary functions. 

 A: Hint A function $$f(x, y) = g(x, y)^2 + h(x, y)^2$$ is zero precisely where $g$ and $h$ are. So, pick a function $j : \Bbb R \to \Bbb R$ that vanishes only at integer values $t$ and is suitably bounded and set $g(x, y) = j(x)$ and  $h(x, y) =  j(y)$.

 For example, $$\Bbb R \to \Bbb R, \qquad t \mapsto \sin \pi t$$ vanishes only at integers $t$, so $$\boxed{f(x, y) := \frac{1}{3} (\sin^2 \pi x + \sin^2 \pi y)}$$ vanishes exactly when both $x$ and $y$ are integers. On the other hand, $$0 \leq |f(x, y)| \leq \frac{1}{3}(1 + 1) < 1 ,$$ so $0$ is the only integer value $f$ assumes.

Remark Any two integers in the image $\operatorname{im} f$ of such a function $f$ must be consecutive, and in particular $\operatorname{im} f$ contains no more than two integers. Suppose not: Let $(x_1, y_1), (x_2, y_2)$ be integer points where $f$ takes on nonconsecutive integer values $c_1, c_2$, say, $c_1 < a < c_2$ for some integer $a$, and pick a path $\gamma : [t_1, t_2] \to \Bbb R^2$ connecting those points not passing through any other integer points. Then, $f \circ \gamma$ is a continuous function $[t_1, t_2] \to \Bbb R$ satisfying $(f \circ \gamma)(t_i) = f(x_i, y_i) = c_i$, $i = 1, 2$, and the Intermediate Value Theorem says that there is some $t \in I$ such that $f(f \circ \gamma)(t) = a$, so $f$ takes on the integer value $a$ at the noninteger point $\gamma(t)$.
A: An extremely trivial example: let $f$ be the constant function
$$f(a,b)=\frac{1}{2}$$
This works because the implication
$$ f(a,b)\in\Bbb Z \implies a,b\in\Bbb Z $$
is vacuously true.
