Can floor functions be used to "cycle" between values?

1.3k Views Asked by At

As I was graphing functions in Desmos graphing calculator, I typed in the function $$\lceil{x-\lfloor{x}\rfloor}\rceil$$

which, after some reasoning, unsurprisingly generates the values $0$ or $1$. My question is, can you - with any given amount of floor and ceiling functions - get a the values $0,1$ and $2$? In general, can you prove that with any amount of floor and ceiling functions you can obtain only whole numbers from $0$ to $n$.

Note???

Modular/remainder functions aren't allowed. I'm still in high school so I would appreciate an informal way of either proving the existence of such a function or actually showing a function that can cycle from $0$ to $n$.

3

There are 3 best solutions below

8
On BEST ANSWER

The function $f(x)$ that cycles through $0,1,...,n-1$ is $f(x) = x \bmod n$. So the question is basically how to write it without using $\operatorname{mod}$.

The largest multiple of $n$ lower than or equal to $x$ is $n \left\lfloor \frac{x}{n} \right\rfloor$ and $\operatorname{mod}$ is the difference between $x$ and this largest multiple of $n$. So, in the end:

$$ f(x) = x - n \left\lfloor \frac{x}{n} \right\rfloor $$

is equivalent to the $\operatorname{mod}$ function and will loop through $0,1,...,n-1$ for sequential $x \in \mathbb{N}$.


[ EDIT ] Also, for an example of a function that loops through the same values, but takes only integer values between them:

$$ \lfloor f(x) \rfloor = \left\lfloor{x}\right\rfloor - n \left\lfloor\frac{x}{n}\right\rfloor $$

4
On

Sure. $x-\lfloor x \rfloor$ is the fractional part of $x$, so it can take any value in the range $[0,1)$.

So $2(x-\lfloor x \rfloor)$ can take any value in the range $[0,2)$, which means $\lceil 2(x-\lfloor x \rfloor) \rceil$ can be any of $0$, $1$, or $2$.

Similarly $n(x-\lfloor x \rfloor)$ can take any value in the range $[0,n)$, which means $\lceil n(x-\lfloor x \rfloor) \rceil$ can take on any integer value between $0$ and $n$ inclusive.

0
On

$\def\floor#1{\lfloor#1\rfloor}$Take any positive integer $n$ and real $x$.

$\floor{x-n\floor{\frac{x}{n}}} = \floor{x} \bmod n$. [This cycles through $0$ to $n-1$ with one unit for each value.]

$\floor{n(x-\floor{x})} = \floor{nx} \bmod n$. [This cycles through $0$ to $n-1$ with period length $1$.]

The easiest way to see why is to notice that $n \floor{\frac{x}{n}}$ is the nearest multiple of $n$ no greater than $x$, so subtracting that from $x$ yields the remainder of $x$ modulo $n$. If you then perform a further floor, you will get the integer part of the remainder, as desired. You can first scale $x$ by a constant before the whole process, to change the period length. This is how we can get the second expression above.