# 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?

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}\\$$

• FYI, the Wikipedia's statements about floor & ceiling function negative values equalities that I used are dealt with in Floor and Ceiling function. Commented Jan 24, 2022 at 21:25
• How does desmos define $a \mod m$ when $m$ is not an integer? $\lceil K \rceil = \begin{cases}\lfloor K \rfloor&K\in \mathbb Z\\ \lfloor K\rfloor + 1&K\not \in \mathbb Z\end{cases}$ so your only issue is whether $\frac aM\in \mathbb Z$ or in other words whether there exists a $k\in \mathbb Z$ so that $a=kM$. This is the definition of $M\mid a$ regardless as to whether $M$ or $a$ are integers or not. If $M\in \mathbb Z$ then this is true precisely when $0=a\mod M$. So your issue is entire based on what $a\mod M$ means when $M\not\in\mathbb Z$. Commented Jan 25, 2022 at 1:02
• For example what is $7 \mod \frac {7}{13}$. We do know that $\frac 7{13} \mid 7$ because there is an integer $\color{blue}{13}$ so that $7 = \color{blue}{13}\cdot \frac {7}{13}$. But does that mean $0 = 7\mod \frac {7}{13}$? What does $7\mod \frac 7{13}$ mean? Commented Jan 25, 2022 at 1:05
• @fleablood Variants of the modulo operation ("mod(x, M)") are presented in Wikipedia Modulo operation. Desmos seems to define "mod" in terms floored division. This can be seen by comparing the graphs in this Desmos Graph to the graphs in the "Quotient and remainder using floored division" image. Commented Jan 25, 2022 at 1:17
• @fleablood As you can see, in both cases, a positive divisor (i.e. M > 0) yields a positive "mod(x, M)"; while a negative divisor (i.e. M' = -M < 0) yields a negative "mod(x, M')". Commented Jan 25, 2022 at 1:23

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}$$