Are there smooth functions that in their limit can perform ceiling and floor operations?

216 Views Asked by At

Preamble

  1. There is a motivation section at the bottom which explains where this arose from -- might be helpful or of interest
  2. There is a set of ideal criteria which if met would define the ideal solution
  3. There a follow on set of less than criteria which relax the ideal criteria -- some readers pointed out that the original criteria are unnecessarily restrictive

Do we have

Ideal Criteria

$1.$ functions like $f(x,\theta)$ and $g(x,\theta)$

$2.$ are defined where $\theta \in {\rm I\!R}^1$ and $x \in {\rm I\!R}^1$

$3.$ are smooth and continuous where $ \left| \theta \right| \lt C$ where $C$ is some constant

$4.$ $f$ and $g$ themselves cannot be defined (make use of) the floor or ceiling functions

$5.$ $f$ and $g$ cannot be defined as different functions over subsets over their domain for example: (,)=0 for ||< and (,)=⌊⌋

$6.$ $f$ and $g$ can make use of $\Sigma$ and $\Pi$ operators

$7.$ $f$ and $g$ can make use of frequency type decomposition

Less than Ideal Criteria -- which may involve relaxing some of the Ideal Criteria

$8.$ a less than ideal solution would allow $\theta$ to be $\in \mathbb{Z}$

$9.$ a less than ideal solution can allow $f$ and $g$ to make of differentiation and integration

$10.$ a borderline admissible solution would allow $f$ and $g$ to a composition of different functions over disjoint subsets over their domain -- in other word relaxing condition $4.$

that we get

$$ \lim_{\theta \to \infty} f(x, \theta) = \lfloor x \rfloor $$

and

$$ \lim_{\theta \to \infty} g(x, \theta) = \lceil x \rceil $$

Motivation

  1. The question really comes from can we implement something in terms of something else -- kinda like how can we use deterministic logic to generate random numbers, or how can we implement a Turing machine using NAND logic

  2. Additionally, more mental itch -- would be great to see floor and ceiling implementations using middle-school or say high-school math

  3. I want a representation off floor and ceiling that is does not make use of the if-then -- say we were to implement floor and ceiling in terms of electrical or mechanical machinery, if-then machinery is complex and expensive

  4. Say we were in a world where analog computers existed where we had black-boxes that did addition, multiplication, power, division, log, but no memory and no if-then/jump type stuff -- could we implement floor and ceiling

  5. Allowing direct memory components such as accumulators or delay operators would not be allowed

2

There are 2 best solutions below

0
On BEST ANSWER

Here's one way of building these functions.

Throughout most of this, I'll be discussing functions with a domain where $\theta > 0$. But at the end, there's a way to fix that up if desired.

First, to get a non-smooth "sharpness", approximate $|x|$ by hyperbolae with $y=\pm x$ as asymptotes:

$$ f_1(x,\theta) = \sqrt{x^2 + \frac{1}{\theta}} $$ $$ \lim_{\theta \to \infty} f_1(x,\theta) = |x| $$

The derivative of this function with respect to $x$ will have a discontinuity in the $\theta \to \infty$ limit, without explicitly being defined with an "if-else", and remaining smooth at all $\theta>0$:

$$ f_2(x,\theta) = \frac{\partial f_1}{\partial x}(x,\theta) = x \left(x^2 + \frac{1}{\theta}\right)^{-1/2} $$ $$ \lim_{\theta \to \infty} f_2(x,\theta) = \begin{cases} -1 & x<0 \\ 0 & x=0 \\ 1 & x>0 \end{cases} $$

Also notice that $|f_2(x,\theta)| < 1$ for all real $x$ and all positive $\theta$.

The "fractional part" function $\{x\} = x - \lfloor x \rfloor$ is periodic, so to work in some periodicity the natural choice is trigonometric functions. One slight catch is that we need the function to be one-to-one on the period between discontinuities, but $\sin$ and $\cos$ are not one-to-one in their periods. But this use of $f_2$ solves that nicely by using half-periods of the trig functions:

$$ f_3(x,\theta) = \cos(\pi x) \, f_2 \big(\!\sin(\pi x), \theta \big) $$ $$ \lim_{\theta \to \infty} f_3(x,\theta) = \begin{cases} 0 & x \in \mathbb{Z} \\ \cos\!\big[\pi (x- \lfloor x \rfloor) \big] & x \notin \mathbb{Z} \end{cases} $$

(If $2n < x < 2n+1$ for some integer $n$, then $\cos(\pi x) = \cos\!\big[\pi(x - 2n) + 2n \pi\big] = \cos\!\big[\pi(x - \lfloor x \rfloor)\big]$, and $f_2$ approaches $+1$ in the limit. If $2n+1 < x < 2n+2$, then $\cos(\pi x) = \cos\!\big[\pi(x - 2n-1) + (2n+1)\pi\big] = -\cos\!\big[\pi(x - \lfloor x \rfloor)\big]$, and $f_2$ approaches $-1$ in the limit.)

Since $|\cos| \leq 1$ and $|f_2| < 1$, $|f_3(x,\theta)| < 1$ on the domain, which means the arccosine is defined. So the next simple step:

$$ f_4(x,\theta) = x - \frac{1}{\pi}\, \cos^{-1}\! \big[ f_3(x,\theta) \big] $$ $$ \lim_{\theta \to \infty} f_4(x,\theta) = \begin{cases} \frac{1}{2} & x \in \mathbb{Z} \\ \lfloor x \rfloor & x \notin \mathbb{Z} \end{cases} $$

@GregMartin mentioned in a comment a way to fix up singleton points, like these at the discontinuities:

$$ f_5(x,\theta) = (\cos^2 \pi x)^\theta $$ $$ \lim_{\theta \to \infty} f_5(x,\theta) = \begin{cases} 1 & x \in \mathbb{Z} \\ 0 & x \notin \mathbb{Z} \end{cases} $$ $$ f_6(x,\theta) = f_4(x,\theta) + \frac{1}{2} f_5(x,\theta) $$ $$ \lim_{\theta \to \infty} f_6(x,\theta) = \lfloor x \rfloor $$

Or written all the way out,

$$ f_6(x,\theta) = x - \frac{1}{\pi} \cos^{-1} \left[ \cos(\pi x) \sin(\pi x) \left(\sin^2(\pi x) + \frac{1}{\theta}\right)^{-1/2} \right] + \frac{1}{2} (\cos^2 \pi x)^\theta $$

This function is smooth everywhere, but its limit at large $\theta$ is not. See a graph of $f_6(x,5)$ on Wolfram Alpha.

If definition on all real $\theta$ is important, instead of just on positive $\theta$, you could take $f_7(x,\theta) = f_6(x,e^\theta)$.

Since $\lceil x \rceil = - \lfloor -x \rfloor$, a similar function approaching $\lceil \cdot \rceil$ is just

$$ g(x,\theta) = -f_6(-x,\theta) $$

[or use $f_7$ in place of $f_6$.]

6
On

For continuous functions, we can take $$ f(x,\theta) = \lfloor x \rfloor + \big( x - \lfloor x \rfloor \big)^\theta. $$ It's easy to convert this to smooth functions, since there is always a smooth function $\tilde f(x,\theta)$ uniformly satisfying $\big| \tilde f(x,\theta) - f(x,\theta) \big| < \frac1\theta$.

In any case, we can take $g(x,\theta) = -f(-x,\theta)$, since $-\lfloor-x\rfloor = \lceil x\rceil$.