Quotient is Primitive Recursive

Theorem
Let $m, n \in \N$ be natural numbers.

Let us define the function $\operatorname{quot}: \N^2 \to \N$:


 * $\operatorname{quot} \left({n, m}\right) = \begin{cases}

\text{the quotient when } n \text{ is divided by } m & : m \ne 0 \\ 0 & : m = 0 \end{cases}$

where the $\text{quotient}$ and $\text{remainder}$ are as defined in the Division Theorem:
 * If $n = m q + r$, where $0 \le r < m$, then $q$ is the quotient.

Then $\operatorname{quot}$ is primitive recursive.

Proof
We note that if $m \ne 0$ and $n = m q + r$, we have $\displaystyle \frac n m = q + \frac r m$.

Of course $\displaystyle \frac n m$ and $\displaystyle \frac r m$ are rational numbers and not necessarily natural numbers.

In fact we have $\displaystyle 0 \le \frac r m < 1$.

So if $m > 0$ then $\operatorname{quot} \left({n, m}\right)$ is the floor $\displaystyle \left \lfloor {\frac n m} \right \rfloor$ of $\frac n m$.

So we have:
 * $\operatorname{quot} \left({n, m}\right) = \begin{cases}

0 & : m = 0 \\ \left \lfloor {\dfrac n m} \right \rfloor & : m \ne 0 \end{cases}$

Then we see that for $m \ne 0$:
 * $\left \lfloor {\dfrac {n + 1} m} \right \rfloor = \begin{cases}

\left \lfloor {\dfrac n m} \right \rfloor + 1 & : m \backslash \left({n + 1}\right) \\ \left \lfloor {\dfrac n m} \right \rfloor & : \text{otherwise} \end{cases}$

So for $m \ne 0$:
 * $\operatorname{quot} \left({n + 1, m}\right) = \begin{cases}

\operatorname{quot} \left({n, m}\right) + 1 & : \operatorname{rem} \left({n + 1, m}\right) = 0 \\ \operatorname{quot} \left({n, m}\right) & : \operatorname{rem} \left({n + 1, m}\right) \ne 0 \end{cases}$

Now note that:
 * $\overline{\operatorname{sgn}} \left({\operatorname{rem} \left({n + 1, m}\right)}\right) = \begin{cases}

1 & : \operatorname{rem} \left({n + 1, m}\right) = 0 \\ 0 & : \operatorname{rem} \left({n + 1, m}\right) \ne 0 \end{cases}$

So the $\operatorname{quot}$ is defined as: (note that the factor $\operatorname{sgn} \left({m}\right)$ is needed to cover the case where $m = 0$).
 * $\operatorname{quot} \left({0, m}\right) = 0$
 * $\operatorname{quot} \left({n + 1, m}\right) = \operatorname{sgn} \left({m}\right) \operatorname{quot} \left({n, m}\right) + \overline{\operatorname{sgn}} \left({\operatorname{rem} \left({n + 1, m}\right)}\right)$

Thus $\operatorname{quot}$ is obtained by primitive recursion (over the first variable, which is allowed by Permutation of Variables of Primitive Recursive Function) from the primitive recursive functions:
 * Signum function $\operatorname{sgn}$
 * Remainder $\operatorname{rem}$
 * Addition
 * Multiplication.

So it follows that $\operatorname{quot}$ is primitive recursive.