Integral division by minimalization

25 Views Asked by At

Given nonnegative integers $m,n$ with $m\geq n>0$. Find $q,r\geq 0$ with $m=q\cdot n + r$, where $0\leq r<n$. Use the formalism of primitive recursive functions and nothing else.

I want to use bounded minimalization: Given $g:{\Bbb N}_0^2\rightarrow{\Bbb N}_0$, define $f:{\Bbb N}_0\rightarrow{\Bbb N}_0$ with $$f(x) = \mu [y\leq z](g(x,y)=0)$$ which is the smallest value $y$ such that $g(x,y)=0$ and $0\leq y\leq z$ (i.e., the search is bounded). If $y$ doesn't exist, the value $y+1$ is output.

In the above case, consider $$\mu[q\leq m](m-q\cdot n=0)$$ where the subtraction $-$ never gets a negative value. Here the cases $m=qn$ and $m\ne qn$ need to be considered which makes it difficult to provide a single expression. One can use the sign function ${\rm sgn}(x)$ which is 1 if $x>0$ and 0 if $x=0$.

1

There are 1 best solutions below

0
On

Well, I have a solution. For this, let $m\geq n>0$.

$f(n,m) = \chi_D(n,m) \cdot \mu[q\leq m](m-q\cdot n=0) + ({\rm csg}(\chi_D(n,m)) \cdot [\mu[q\leq m](m-q\cdot n=0) - 1],$

where $\chi_D(n,m) = 1$ if $n$ divides $m$ and $0$ otherwise and subtraction is ''conditional'', i.e., $x-y = 0$ if $x\leq y$, and the co-sign function is ${\rm csg}(x) = 0$ if $x>0$ and $1$ if $x=0$.

Example:

$m=6$ and $n=2$. Then the first summand yields the result: $\chi_D(2,6) = 1$ and $\mu[q\leq m](m-q\cdot n=0)$ yields $q=3$: $7=3\cdot 2$.

$m=7$ and $n=2$. Then the second summand provides the result: ${\rm csg}(\chi_D(2,7)) = 1$ and $\mu[q\leq m](m-q\cdot n=0)$ yields $q=4$ so that we need to subtract 1: $7=3\cdot 2+1$.

Since all involved functions are primitive recursive, the function $f$ is primitive recursive. Done.