TITLE: Is the following proof of the continuity of a function correct?
QUESTION [6 upvotes]: I just started learning analysis and encountered my first task on continuity today, namely proving that $f: \mathbb{R}\to \mathbb{R}, \space f(x) = \inf\{|x-k\rvert \space \mid k\in \mathbb{Z} \}$ is continuous in every point. I attempted to prove this as follows:
Let $x_{0} \in \mathbb{R}$ be arbitrary. Let $x \in \mathbb{R}$. By the triangle inequality we have $\left|x_{0}-k\right| \leq\left|x_{0}-x\right|+|x-k|$ for all $k \in \mathbb{Z}$. Thus, one obtains
$$
\inf \left\{\left|x_{0}-k\right| \mid k \in \mathbb{Z}\right\} \leq\left|x_{0}-x\right|+\inf \{|x-k| \mid k \in \mathbb{Z}\}
$$
so by the definition of $f$
$$
f\left(x_{0}\right)-f(x) \leq\left|x_{0}-x\right|
$$
so we obtain  $f(x)-f\left(x_{0}\right) \leq$
$\left|x_{0}-x\right|$ (applying the same argumentation). We get
$$
\left|f\left(x_{0}\right)-f(x)\right| \leq\left|x_{0}-x\right|
$$
Now, let $\epsilon>0$ be arbitrary. To show that $f$ is continuous in $x_{0}$ we must find some  $\delta>0$, s.t. for all $x \in \mathbb{R}$ with $\left|x-x_{0}\right|<\delta$ the inequality $\left|f\left(x_{0}\right)-f(x)\right|<\epsilon$ holds. From the above we can clearly see that $\delta=\epsilon$ is a sufficient choice is. Since $x_{0}$ was arbitrary, we are done.
Does this attempt seem valid? Also, what are other ways one could prove this (assuming that the above works). I assume that one often can just plug in the definition of the respective function and then rearrange the inequality, but this didn‘t quite work for me in this case.

REPLY [2 votes]: Your estimate appears to be correct.  If you draw a picture, this function is a "sawtooth" function.   For $n\in \mathbb{Z}$, you have $f(n) = 0$ and $f(n + 1/2) = 1/2$. The rest of the graph can be obtained by "connecting the dots."  The slopes of the connecting lines are $\pm 1$.  So, you do have $|f(x) - f(y)| \le |x - y|$ for all $x, y\in \mathbb{R}$.