8

I've been working on Project Euler and have found myself using the floor and ceiling functions a lot. I was hoping somebody could help me figure out how distribution and other properties of these functions work.

  1. Is floor(x) + floor(y) = floor(x+y) ?
  2. Is floor(x) = y the same as x = ceil(y) and vice-versa?

Remember, I'm asking about all real numbers, not just integers. Are there any other rules about floor/ceil I should know about?

Thanks!

3 Answers3

6

I managed to find a list of properties of ceil and floor functions in this blog: https://janmr.com/blog/2009/09/useful-properties-of-the-floor-and-ceil-functions/ It contains various relations between these functions, their results and argument values. It also contain some references for further reading.

Please find below some of these properties for real numbers.

(In)equalities

$$ x - 1 < \lfloor x \rfloor \leq x \leq \lceil x \rceil < x + 1 $$ $$ \lfloor -x \rfloor = -\lceil x \rceil $$ $$ \lfloor x \rfloor + k = \lfloor x + k \rfloor $$ $$ \lceil x \rceil + k = \lceil x + k \rceil $$

$$ \Bigl\lfloor \frac{n}{m}\Bigr\rfloor = \Bigl\lceil \frac{n - m + 1}{m} \Bigr\rceil $$

$$ \Bigl\lceil \frac{n}{m}\Bigr\rceil = \Bigl\lfloor \frac{n + m - 1}{m} \Bigr\rfloor $$

Increasing functions

If a function $f: \mathbb{R} \rightarrow \mathbb{R} $ is continuous and monotonically increasing and for each integer $f(x)$ the value of $x$ is also an integer (e.g. $f(x) = \sqrt{x}$), we have:

$$ \lfloor f( \lfloor x \rfloor ) \rfloor = \lfloor f(x) \rfloor $$

$$ \lceil f( \lceil x \rceil ) \rceil = \lceil f(x) \rceil $$

Logarithms

For integer $k$ and all $b > 0$, $b \neq 1$:

$$ k =\lfloor \log_b{x} \rfloor \Leftrightarrow b^k \leq x < b^{k + 1} $$

$$ k = \lceil \log_b{x} \rceil \Leftrightarrow b^{k - 1} < x \leq b^k $$

References

The references are taken from the blog above:

  • "Concrete Mathematics" by R. L. Graham, D. E. Knuth, and O. Patashnik
  • "The Art of Computer Programming", Volume 1, by Donald E. Knuth.
xdaimon
  • 77
scrutari
  • 279
4

Your statements are both false. Here are counter-examples:

For $x=y=.5$, $\lfloor x \rfloor +\lfloor y\rfloor=0$, but $\lfloor x+y \rfloor=1$.

For $x = .5$, $y=0$, we have $\lfloor x \rfloor =0$ but $\lceil y \rceil = 0 \neq .5$.

It is true that $\lfloor x +y \rfloor - 1 \leq \lfloor x \rfloor + \lfloor y \rfloor \leq \lfloor x+y \rfloor$, because, writing $x = \lfloor x \rfloor + \alpha$, $y = \lfloor y \rfloor + \beta$, we have $0 \leq \alpha,\beta < 1$, and $x + y = \lfloor x \rfloor + \lfloor y \rfloor + \alpha + \beta$. Then: $$ \lfloor x + y \rfloor = \lfloor x \rfloor + \lfloor y \rfloor + \lfloor \alpha + \beta \rfloor, $$ and $\lfloor \alpha+\beta \rfloor$ is either $0$ or $1$.

1

Your proposed identities aren't true (already explained in another answer), but this identity is true:

$$\lfloor x \rfloor = -\lceil -x \rceil.$$

David K
  • 98,388