convert ceil to floor

1.7k Views Asked by At

Mathematically, why is this true?

$$\left\lceil\frac{a}{b}\right\rceil= \left\lfloor\frac{a+b-1}{b}\right\rfloor$$

Assume $a$ and $b$ are positive integers.

Is this also true if $a$ and $b$ are real numbers?

5

There are 5 best solutions below

1
On BEST ANSWER

This is not true in general, e.g. take $b = 1/2$ and $a = 2,$ so the LHS is $4$ while the RHS is $3.$

Suppose $b\nmid a,$ since that case is trivial. Use the division algorithm to write $a = qb + r,$ where $q \in \mathbb{N}\cup \{0\}$ and $0 < r < b.$ Then the LHS is $q+1$ while the RHS is $\lfloor (q+1) + \frac{r-1}{b} \rfloor.$ Since $r$ is in fact an integer, $b > r \ge 1$ yields $\frac{b-1}{b} > \frac{r-1}{b} \ge 0,$ whence $\lfloor (q+1) + \frac{r-1}{b} \rfloor = q+1,$ as desired.

Edit: I was a bit hasty in giving the general condition. Here it is corrected.

If $b \mid a,$ then the LHS is $q$ and $r = 0,$ so you need $b \ge 1$ for the RHS to also be $q.$ If $b\nmid a,$ we write $a = qb + r,$ where $q \in \mathbb{Z}$ and $0 < r < |b|.$

So we need $0 \le \frac{r-1}{b} < 1.$ If $b > 0,$ this occurs so long as $r \ge 1$ (which in particular means that $b > 1$).

If $b < 0,$ then we need $r > 1 + b.$ Now, we also have $r < |b| = -b,$ which gives $-b > 1 + b,$ or $b < -1/2.$ For $b \le -1,$ $r > 1+b$ holds trivially, and for $-1 < b < -1/2,$ one has to actually check that $r > 1 +b.$

0
On

Let $$\text{ceil}(a/b) = n \implies a = bn-r, \text{ where } r\in \{0,1,\ldots,b-1\}$$ This gives us $$a+b-1 = bn-r+b-1 = bn + (b-1-r), \text{ where }r \in \{0,1,\ldots,b-1\}$$ Hence, $$a+b-1 = bn + s, \text{ where }s \in \{0,1,\ldots,b-1\}$$ Thereby, $$\text{floor}((a+b-1)/b) = n = \text{ceil}(a/b)$$

2
On

Suppose, $b\nmid a$. Let $\lfloor\frac{a+b-1}{b}\rfloor=n \implies nb+r=a+b-1$ where $0\leq r<b$. So $\frac{a}{b}+1=n+\frac{r+1}{b}$. So $\lfloor\frac{a}{b}+1\rfloor=\lceil\frac{a}{b}\rceil=n$.

This is not true in general as shown by Lyj.

0
On

$$\left\lceil \frac { a }{ b } \right\rceil =\frac { a }{ b } +1-\left( \frac { a }{ b } \mod\ 1 \right) ,\quad \quad (1)$$

$$\left\lfloor \frac { a+b-1 }{ b } \right\rfloor =\frac { a+b-1 }{ b } -\left( \frac { a+b-1 }{ b } \mod\ 1 \right) =\frac { a }{ b } +1-\frac { 1 }{ b } -\left( \frac { a }{ b } -\frac { 1 }{ b } \mod\ 1 \right) ,\quad \quad (2)$$

For the sake of simplicity write $$\left( \frac { a }{ b } \mod\ 1 \right) =k$$ The equations $(1)$ and $(2)$ are equal: $$\frac { a }{ b } +1-k=\frac { a }{ b } +1-\frac { 1 }{ b } -k+\left( \frac { 1 }{ b } \mod\ 1 \right) $$ Finally, $$\frac { 1 }{ b } =\left( \frac { 1 }{ b } \mod 1 \right) .$$ For $b>1$ your claim holds.

I think that something is missing. Until the next edit...

0
On

If $\frac{a}{b}$ is not an integer and $\frac{a}{b} > n + \frac{1}{b}$, where $n$ is an integer, then it is easy to see that $$\left\lceil\frac{a}{b}\right\rceil= \left\lfloor\frac{a}{b}+1-\frac{1}{b}\right\rfloor.$$ If $\frac{a}{b}$ is an integer then the relationship $$\left\lceil\frac{a}{b}\right\rceil= \left\lfloor\frac{a}{b} + 1 - \frac{1}{b}\right\rfloor$$ holds.

The only situation which causes problem is when $\frac{a}{b} \in [n, n+\frac{1}{b})$, where $n$ is an integer.This is not going to happen since $a$ is a positive integer. Clearly, the above statement doesn't hold true if $a$ is real.