Some identities involving integer division

I have worked out quite some identities involving integer division while writing other articles, and I decided to write them down for reference.

The variables , , are assumed to be integers (with ) throughout this article, whereas is a real variable.

Rounding up and down

When we divide unsigned integers n and d, the result gets rounded down. That is, n / d evaluates to . If we want to round up the quotient, we can do it as (n + d - 1) / d. Here, we are using the following identity:

The relation between the floor and the ceil function is that

Rounding to multiples of

To round down an integer to the nearest multiple of , we can use the expression . Alternatively, we can use modular arithmetic to write this expression as

Likewise, we can round up an integer to the nearest multiple of with the expression . With modular arithmetic we can write this as

Getting rid of floor/ceil

Sometimes, it is useful to get rid of the floor or ceiling function from an expression. From the results in the last section we can derive the following identities which allow you to do this.

For the floor function, we have:

And for the ceil function:

Sum identity

I write , , so that we have .

By working out we can prove that

Likewise, we can write , , so that .

Then, we can work out and get the identity

Product identity

Again, I write , , so that we have .

By working out and simplifying the expression we can prove that

Again writing , , we have .

Now we can work out and get the identity