Is there an equivalence between $\big\lceil \frac{a}{M} \big\rceil$ and $floor$ that works regardless of wether $a$ and/or $M$ are integers or not?

78 Views Asked by At

Is there a way to rewrite a $ceiling$ as a $floor$?

I want to write $\big\lceil \frac{a}{M} \big\rceil$ in terms of $floor$ and possibly $\bmod M$ if necessary.

Given $q := \big\lfloor \frac{a}{M} \big\rfloor$ and $r = a \bmod m$, I thought the following were equivalent

$$ \begin{aligned} \Big\lceil \frac{a}{M} \Big\rceil &= \begin{cases} q &\;\text{if }\ r = 0\\ q+1 &\;\text{if }\ r \neq 0 \end{cases} &&(1)\\ \\ &= \Big\lfloor \frac{a-1+M}{M} \Big\rfloor &&(2)\\ \\ &= \Big\lfloor \frac{a-1}{M} \Big\rfloor + 1 &&(3) \end{aligned} $$

But after graphing them on Desmos, I've come to find out the latter two, $(2)$ and $(3)$, seem to be equivalent to $\big\lceil \frac{a}{M} \big\rceil$ iif $a$ and $M$ are integers or something like that. Maybe $a$ and $M$ have to be positive as well for $(2)$ and $(3)$ to be equivalent to $(1)$.

Is there an equivalence between $\big\lfloor \frac{a}{M} \big\rfloor$ and $floor$ ((other than the equivalence shown in $(1)$)) that works regardless of wether $a$ and/or $M$ are integers or not?


By the way, using $Iverson\ bracket\ notation$, $(1)$ can be written as

$$ \begin{aligned} \Big\lceil \frac{a}{M} \Big\rceil &= \Big\lfloor \frac{a}{M} \Big\rfloor + [[a \bmod M \neq 0]] \end{aligned} $$

where $[[condition]]$ denotes $Iverson\ bracket\ notation$ defined as

$$ [[condition]]= \begin{cases} 1 &\text{if } condition\\ 0 &\text{otherwise} \end{cases}\\ $$

1

There are 1 best solutions below

0
On BEST ANSWER

As stated in the Relations among the functions section of Wikipedia's article, for any $x \in \mathbb{R}$, we have $-\lceil x \rceil = \lfloor -x \rfloor$, which means

$$\lceil x \rceil = -\lfloor -x \rfloor \tag{1}\label{eq1A}$$

To prove this, let $x = n + r$, where $n \in \mathbb{Z}$, $r \in \mathbb{R}$ and $0 \le r \lt 1$. If $r = 0$, then $\lceil x \rceil = n$ and $-\lfloor -x \rfloor = -(-n) = n$. If $r \gt 0$, then $\lceil x \rceil = n + 1$ while $-\lfloor -x \rfloor = -\lfloor -n - r \rfloor = -(-n - 1) = n + 1$.

Thus, \eqref{eq1A} holds for both cases. For your particular expression, using $x = \frac{a}{M}$ in \eqref{eq1A} gives

$$\left\lceil \frac{a}{M} \right\rceil = -\left\lfloor -\frac{a}{M} \right\rfloor \tag{2}\label{eq2A}$$