# Showing how one definition of div follows from another

how can I do a formal proof of the following description:

$a\;div\;b = \begin{cases} \lfloor \frac{a}{b} \rfloor &\text{ if }b>0\\ \lceil \frac{a}{b} \rceil &\text{ if }b<0 \end{cases}\\$

It seems pretty straight forward as $a$ div $b$ is defined as $q$ from the expression $a=q b + r$, where r has to be a positive integer smaller than b.

-
I believe is $a=qb+r$ with $0\leq r<b$ positive integer. –  P.. Dec 10 '12 at 20:48
Just use the definition of the floor function. –  Adeel Dec 10 '12 at 20:48
Thank you @Pambos; you're right. @Adeel - well I know what floor and ceil functions do, but even then it seems trivial that q has to be largest integer not greater than the quotient (if b>0) and the otherway around for b<0... –  smihael Dec 10 '12 at 20:49

If $b\mid a$ is easy. So assume that $b\nmid a$.
Let $k$ be the largest integer that is smaller to $\dfrac{a}{b}$, i.e. $k$ is the integer with the property $k<\dfrac{a}{b}<k+1$.
If $b>0$ then for $0<s=\dfrac{a}{b}-k<1$ we have $a=kb+sb$ and $0 <sb<b$. Therefore $a \text{ div } b=k=\lfloor\dfrac{a}{b}\rfloor$.
If $b<0$ then for $0<s=k+1-\dfrac{a}{b}<1$ we have $a=(k+1)b-sb$ and $0 <-sb<b$. Therefore $a \text{ div } b=k+1=\lceil\dfrac{a}{b}\rceil$.