TITLE: Formula for the floor function
QUESTION [8 upvotes]: I found the following formula for the floor function:
$$\lfloor x \rfloor = -\frac12+x+\frac{\arctan(\cot\pi x)}{\pi}$$
for all $x$ not an integer.
My question is where I can find the proof of this formula.

REPLY [2 votes]: Consider 
$$f(x) = \frac{1}{\pi}\int_{0}^{\cot(\pi x)}\frac{dy}{1+y^2}=\frac{\arctan(\cot(\pi x))}{\pi},$$
with the latter equation obtained by substituting $y=\tan u.$  Since $x\to \cot(\pi x)$ is manifestly periodic of period $1,$ and $f$ integrates to $0$ over one period (since $\cot$ is an odd function), $f$ also is periodic.
When $x$ is not an integer $f$ is differentiable at $x$ because both $\cot(\pi x)$  and the integral (qua function of its upper limit) are. The Chain Rule and Fundamental Theorem of Calculus together imply 
$$f^\prime(x) = \frac{1}{\pi}\left(\frac{1}{1 + (\cot(\pi x))^2}\right) \frac{d}{dx}\left(\cot(\pi x)\right)=\frac{-\pi\csc(\pi x)^2}{\pi\csc(\pi x)^2}=-1.$$
This is the key insight, because it shows $f$ has the basic properties needed to construct functions that are periodic and linear between their points of discontinuity.  The rest is just algebra.
Since $f(1/2)$ is an integral from $0$ to $0=\cot(\pi/2),$
$$f(1/2) = 0.$$
This information completely determines $f.$  To summarize, at nonintegral values $f$ falls linearly with slope $-1,$ equals $0$ at $1/2,$ and repeats this pattern between each successive pair of integers.  Consequently the function
$$\frac{1}{2} - f(x)$$
must rise linearly from $0$ at $x=0$ up to a limit of $1$ as $x\to 1.$  Because it is periodic, it drops back to $0$ when $x=1$ and repeats this pattern ad infinitum in both directions.  Obviously that describes the remainder ("fractional part") function.  That is,
$$x - \lfloor x \rfloor = \frac{1}{2} - f(x).$$
Solving for the floor,
$$\lfloor x \rfloor = x - \left( \frac{1}{2} - f(x)\right) = -\frac{1}{2} + x + \frac{\arctan(\cot(\pi x))}{\pi}.$$