Differentiable analogue of greatest integer (a.k.a. floor) function

65 Views Asked by At

The floor function is not differentiable at integral values in the real domain. However, we can build a new function defined as: $$x+\left(\frac{2}{1+\exp{(-k \sin(\pi x))}}-1\right)\frac{\arcsin(\cos(\pi x))}{\pi}-\frac{1}{2}$$ As shown here, for large values of $k$, the function is a pretty good approximation of the floor function, with the added benefit of it being smooth and continuous. The function was built with a mix of the sigmoid function with a repeating triangular signal function. enter image description here

The only problem with my function is that as $k$ tends to infinity, integer values $n$ are mapped to $n+0.5$ instead of $n$

Now my question is this: What other smooth and continuous functions can be used to approximate the floor function?

Additional context: This question came to my mind when I read about the swish function being better than the ReLU function for being differentiable.