[Math] Why is this combination of nearest-integer functions — surprisingly — continuous

continuitydiscrete mathematics

Alright, I didn't know the best way to formulate my question. Basically, whilst doing some physics research, I naturally came upon the function

$$ f(x) = 2x[x] – [x]^2 $$

where I use $[x]$ as notation for the `nearest-integer function' (i.e. rounding off). Usually this function has to have a caveat of how we exactly define the value for $x \in \frac{1}{2} \mathbb Z$, but interestingly for this function it does not matter, since it turns out to be continuous! In fact, it turns out $f(x)$ is exactly given by the glued function of taking all the tangent lines of $x^2$ at integer values of $x$:

enter image description here
(Note: due to properties of $x^2$, the tangent lines exactly intersect at half-integer values of $x$.)

So my question is not literally `why is it continuous?', but rather: considering it is continuous, and considering that that is not a generic property of functions which are defined in terms of nearest-integer functions, is there a better (i.e. more insightful) way of expressing $f(x)$? Relatedly, is there some part of mathematics where functions similar to these naturally arise?

Best Answer

Let $g(x,y)$ be any continuous function such that $g(x,-\frac12)=g(x,\frac12)$. Then $f(x)=g(x,x-[x])$ is continuous.

In particular, your function is given by $g(x,y)=x^2-y^2$. Consequently, we can write $f(x)=x^2 - (x-[x])^2$.