|
|
|
|
examples of primitive recursive functions
|
(Example)
|
|
|
Starting from the simplest primitive recursive functions, we can build more complicated primitive recursive functions by functional composition and primitive recursion. In this entry, we have listed some basic examples using functional composition alone. In this entry, we list more basic examples, allowing the use of primitive recursion:
- $\operatorname{add}(x,y)=x+y$ : $\operatorname{add}(x,0)=\operatorname{id}(x)$ , and $\operatorname{add}(x,n+1)=s(\operatorname{add}(x,n))$
- $\operatorname{mult}(x,y)=xy$ : $\operatorname{mult}(x,0)=z(x)$ , and $\operatorname{mult}(x,n+1)=\operatorname{add}(x,\operatorname{mult}(x,n))$ .
- $p_2(x)=x^2$ , which is just $\operatorname{mult}(x,x)$ ; more generally, $p_{m+1}(x)=\operatorname{mult}(x,p_m(x))$ , which is primitive recursive by induction on $m$
- $\exp_m(x)=m^x$ : $\exp_m(0)=s(0)$ , and $\exp_m(n+1)=\operatorname{mult}(\operatorname{const}_m(n),\exp_m(n))$
- $\exp(x,y)=x^y$ : $\exp(x,0)=\operatorname{const}_1(x)$ , and $\exp(x,n+1)=\operatorname{mult}(x,\exp(x,n))$
- $\operatorname{fact}(x)=x!$ : $\operatorname{fact}(0)=s(0)$ , and $\operatorname{fact}(n+1)=\operatorname{mult}(s(n),\operatorname{fact}(n))$
-
built using $z$ and $s$ : $\operatorname{sub}_1(0)=z(0)$ , and $\operatorname{sub}_1(n+1)= s(\operatorname{sub}_1(n))$ ;
- more generally, $\operatorname{sub}_m(x)=x\dot{-}m$ may be defined: $\operatorname{sub}_m=\operatorname{sub}_1^m$ .
- $\operatorname{sub}(x,y)=x\dot{-}y$ : $\operatorname{sub}(x,0)=\operatorname{id}(x)$ , and $\operatorname{sub}(x,n+1)=\operatorname{sub}_1(\operatorname{sub}(x,n))$ .
- $\operatorname{diff}(x,y)=|x-y|:=\operatorname{sub}(x,y)+\operatorname{sub}(y,x)$
-
built using $\operatorname{const}_1$ and $z$ : $d_0(0)=\operatorname{const}_1(0)$ , and $d_0(n+1)=z(d_0(n))$ .
- more generally,
is primitive recursive, for it is $d_0(\operatorname{diff}(x,\operatorname{const}_m(x))$ .
- even more generally,
where $S=\lbrace a_1,\ldots,a_m\rbrace$ , is primitive recursive, for it is $d_{a_1}+\cdots +d_{a_m}$ .
-
which is just $\operatorname{sub}(\operatorname{const}_1(x),d_0(x))$ .
-
where $x\!\!\!\mod\! y$ is the remainder of $x\div y$ . Suppose $y\ne 0$ . Then $0\!\!\!\mod\! y=0$ . In addition,
Then $\operatorname{rem}(0,y)=z(y)$ , and \begin{eqnarray*} \operatorname{rem}(n+1,y) &=& \operatorname{sgn}(y) (\operatorname{rem}(n,y)+1)\operatorname{sgn}(|\operatorname{rem}(n,y)+1 - y|) \\ &=& \operatorname{mult}(\operatorname{sgn}(y),\operatorname{mult}(s(\operatorname{rem}(n,y)),\operatorname{sgn}(\operatorname{diff}(s(\operatorname{rem}(n,y)),y)))) \\ &=& g(y,\operatorname{rem}(n,y)) \end{eqnarray*}where $g(y,x):=\operatorname{mult}(\operatorname{sgn}(y),\operatorname{mult}(s(x),\operatorname{sgn}(\operatorname{diff}(s(x),y))))$ . The reason for including $\operatorname{sgn}(y)$ is to account for the case when $y=0$ .
-
To see that $q$ is primitive recursive, we use equation $$x=yq(x,y)+\operatorname{rem}(x,y)$$ obtained from the division algorithm for integers. Then $$yq(x,y)+\operatorname{rem}(x,y)+1 = x+1 = yq(x+1,y)+\operatorname{rem}(x+1,y).$$ Simplify and we get $$y(q(x+1,y)-q(x,y))=\operatorname{rem}(x,y)+1 -\operatorname{rem}(x+1,y).$$ Thus, by the previous example, we get
Therefore, $q(0,y)=z(y)$ , and $$q(n+1,y)=\operatorname{sgn}(y)(q(n,y)+\operatorname{sgn}(\operatorname{diff}(s(\operatorname{rem}(n,y)),y)))$$ where $\operatorname{sgn}(y)$ takes the case $y=0$ into account.
Remarks.
- All of the functions above are in fact examples of elementary recursive functions.
- Example 3(m) above is a special case of a more general phenomenon. Recall that a subset $S\subseteq \mathbb{N}^n$ is called primitive recursive if its characteristic function $\varphi_S$ is primitive recursive. If we take $S=\lbrace m\rbrace$ , then $\varphi_S=d_m$ . Furthermore, a predicate $\Phi(\boldsymbol{x})$ over $\mathbb{N}^k$ is primitive recursive if the corresponding set $S(\Phi):=\lbrace \boldsymbol{x}\in \mathbb{N}^k \mid
\Phi(\boldsymbol{x})\rbrace$ is primitive recursive.
- The technique of bounded maximization may be used to prove the primitive recursiveness of the quotient and the reminder functions in examples 3(o) and 3(p). See this entry for more detail.
|
"examples of primitive recursive functions" is owned by CWoo.
|
|
(view preamble | get metadata)
Cross-references: quotient, primitive, bounded maximization, predicate, characteristic function, subset, elementary recursive functions, functions, division algorithm for integers, equation, remainder, even, induction, primitive recursion, composition, functional, primitive recursive functions
There are 4 references to this entry.
This is version 14 of examples of primitive recursive functions, born on 2009-11-05, modified 2009-12-29.
Object id is 11973, canonical name is ExamplesOfPrimitiveRecursiveFunctions.
Accessed 600 times total.
Classification:
| AMS MSC: | 03D20 (Mathematical logic and foundations :: Computability and recursion theory :: Recursive functions and relations, subrecursive hierarchies) |
|
|
|
|
|
|
Pending Errata and Addenda
|
|
|
|
|
|
|
|
|
|
|