Are these trigonometric expressions for the ceiling and floor functions correct? I believe that I have found a trigonometric expression for both the ceiling and floor function, and I seek confirmation that it is, indeed, correct.
Update.
$$\begin{align}
\lfloor x \rfloor &= x - \frac12+f(x) \\[4pt] 
\lceil  x \rceil  &= x + \frac12+g(x)
\end{align}$$
where
$$\begin{align}
f(x) &= \begin{cases}
\frac12, & x\in\Bbb{Z} \\[4pt]
0, &x=\frac12n, n\in\Bbb{Z} \\[4pt]
\frac1\pi \tan^{-1}(\cot(\pi x)), &\text{otherwise}
\end{cases} \\[10pt]
g(x) &= \begin{cases}
-\frac12, & x\in\Bbb{Z} \\[4pt]
0, &x=\frac12n, n\in\Bbb{Z} \\[4pt]
\frac1\pi \tan^{-1}(\cot(\pi x)), &\text{otherwise}
\end{cases}
\end{align}$$
 A: If you're using the single-valued $\arctan$, i.e. $-\frac{\pi}{2} \leq \arctan(x) \leq \frac{\pi}{2}$, which is what all computer languages I've seen use, this works perfectly fine.
Proof:
Let $x = s(a + b)$, where $a \in \mathbb{N}$, $0 \leq b < 1$ and $s \in \{-1,1\}$. We can call $a$ the absolute integer part, $b$ the absolute fractional part, and $s$ is $x$'s sign.
Then:
$$
\begin{align*}
\frac{\arctan(\cot(\pi x))}{\pi}
&= \frac{\arctan(\cot(\pi s(a + b)))}{\pi}\\[1em]
&= \frac{\arctan(s\cdot\cot(\pi a + \pi b)))}{\pi}\\[1em]
&= \frac{\arctan(s\cdot\cot(\pi b))}{\pi}\\[1em]
&= \frac{\arctan(s\cdot\tan(\frac{\pi}{2} - \pi b))}{\pi}\\[1em]
&= \frac{\arctan(s\cdot\tan(\pi(\frac{1}{2} - b)))}{\pi}\\[1em]
&= \frac{\arctan(\tan(\pi s(\frac{1}{2} - b)))}{\pi}\\[1em]
&= \frac{\pi s(\frac{1}{2} - b)}{\pi}\\[1em]
&= s\bigg(\frac{1}{2} - b\bigg)\\[1em]
\end{align*}
$$
Note that we can assert that $\arctan(\tan(\pi s(\frac{1}{2} - b)) = \pi s(\frac{1}{2} - b)$ without issues only because
$$
\begin{alignat*}{5}
0           && \quad \leq &&  b \quad && < \quad &&  1 &&\implies\\[0.5em]
0           && \quad \geq && -b \quad && > \quad && -1 &&\implies\\[0.5em]
\frac{1}{2} && \quad \geq && \quad \frac{1}{2} - b  \quad && > \quad && -\frac{1}{2} &&\implies\\[0.5em]
\frac{\pi}{2} && \quad \geq &&\ \ \ \pi\Bigg(\frac{1}{2} - b\Bigg) \quad && > \quad && -\frac{\pi}{2} &&\\
\end{alignat*}
$$
$\arctan(\tan(x)) = x$ only holds for $x$ in that range. For example, $\arctan(\tan(x)) = x - \pi$ if $\frac{\pi}{2} < x < \pi$.
With that said...
$$
\begin{align*}
\lfloor x \rfloor &= x - \frac{1}{2} + s\bigg(\frac{1}{2} - b\bigg)\\[0.5em]
&= s(a + b) - \frac{1 - s}{2} - sb\\[0.5em]
&= s(a + b - b) - \frac{1 - s}{2}\\[0.5em]
&= sa - \frac{1 - s}{2}\\[0.5em]
\end{align*}
$$
If $s=1$, $\lfloor x\rfloor = a - \frac{1 - 1}{2} = a$.
If $s=-1$, $\lfloor x\rfloor = -a - \frac{1 + 1}{2} = -a - 1 = -(a + 1)$.
This works because $\lfloor \pm y.uwv \rfloor$ is y if the number is positive, and $-(y + 1)$ if the number is negative. e.g. $\lfloor 1.2\rfloor = 1$ but $\lfloor -1.2\rfloor = -2$.
Proving that your $ceil$ function works should go about the same way.
I realize I am three years late to this but I initially was going to post my own trigonometric floor:
$$
\lfloor x \rfloor = x - \text{frac}(x)\\[1.4em]
%
\text{frac}(x) = \text{sgn}\Big(\sin(2\pi x)\Big)\Bigg( \frac{\cos^{-1}(\cos(2\pi x))}{2\pi} - \frac{1}{2} \Bigg) + \frac{1}{2}\\[1.4em]
%
\text{sgn}(x) = \frac{1}{2}\Bigg(\frac{\cot^{-1}(x) - \cot^{-1}(-x)}{\big|\cot^{-1}(x)\big|}\Bigg)
$$
But yours seems a bit simpler.
A: Note that you have the identity $\tan\left(\frac{\pi}{2}-x\right)=\cot(x)$. Using this, your formula for the floor function is:
$$
\begin{split} \lfloor x \rfloor &= x-\frac{1}{2}+\frac{\arctan\left(\tan\left(\frac{\pi}{2}-\pi\cdot x\right)\right)}{\pi} \\ &=x-\frac{1}{2}+\frac{\frac{\pi}{2}-\pi\cdot x+n\pi}{\pi}, \text{ for }n\in\mathbb{Z} \\ &=x-\frac{1}{2}+\frac{1}{2}-x+n \\ &=n \end{split}
$$
Then there is some $n\in \mathbb{Z}$ such that $n=\lfloor x \rfloor$. If, as usual, you insist that $-\pi\le \arctan(x) \le \pi$ this then forces:
$$
\begin{split} && -1\le \frac{1}{2}-x+n \le 1 \\ &\implies& -\frac{3}{2}\le n-x \le \frac{1}{2} \\ &\implies& x-\frac{3}{2} \le n \le x+\frac{1}{2} \end{split}
$$
So the value for $n$ is close to $\lfloor x \rfloor$. I'm not sure how computers choose which value to pick for $\arctan$ but it appears to always pick the right one for your formula to work. I'm not sure it would be a good idea to use this formula in your work unless you know which value of $\arctan$ to pick to ensure that you get the right answer.
