PlanetMath (more info)
 Math for the people, by the people. Sponsor PlanetMath
Encyclopedia | Requests | Forums | Docs | Wiki | Random | RSS  
Login
create new user
name:
pass:
forget your password?
Main Menu
Owner confidence rating: Very high Entry average rating: No information on entry rating
[parent] 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:

  1. $\operatorname{add}(x,y)=x+y$ : $\operatorname{add}(x,0)=\operatorname{id}(x)$ , and $\operatorname{add}(x,n+1)=s(\operatorname{add}(x,n))$
  2. $\operatorname{mult}(x,y)=xy$ : $\operatorname{mult}(x,0)=z(x)$ , and $\operatorname{mult}(x,n+1)=\operatorname{add}(x,\operatorname{mult}(x,n))$ .
  3. $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$
  4. $\exp_m(x)=m^x$ : $\exp_m(0)=s(0)$ , and $\exp_m(n+1)=\operatorname{mult}(\operatorname{const}_m(n),\exp_m(n))$
  5. $\exp(x,y)=x^y$ : $\exp(x,0)=\operatorname{const}_1(x)$ , and $\exp(x,n+1)=\operatorname{mult}(x,\exp(x,n))$
  6. $\operatorname{fact}(x)=x!$ : $\operatorname{fact}(0)=s(0)$ , and $\operatorname{fact}(n+1)=\operatorname{mult}(s(n),\operatorname{fact}(n))$
  7. \begin{displaymath} % latex2html id marker 249\operatorname{sub}_1(x)=x\dot{-}... ...rm{if } x =0, \ x-1 & \textrm{otherwise,} \end{array}\right. \end{displaymath}
    built using $z$ and $s$ : $\operatorname{sub}_1(0)=z(0)$ , and $\operatorname{sub}_1(n+1)= s(\operatorname{sub}_1(n))$ ;
  8. more generally, $\operatorname{sub}_m(x)=x\dot{-}m$ may be defined: $\operatorname{sub}_m=\operatorname{sub}_1^m$ .
  9. $\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))$ .
  10. $\operatorname{diff}(x,y)=|x-y|:=\operatorname{sub}(x,y)+\operatorname{sub}(y,x)$
  11. \begin{displaymath} % latex2html id marker 251d_0(x):= \left\{ \begin{array}{l... ...xtrm{if } x =0, \ 0 & \textrm{otherwise.} \end{array}\right. \end{displaymath}
    built using $\operatorname{const}_1$ and $z$ : $d_0(0)=\operatorname{const}_1(0)$ , and $d_0(n+1)=z(d_0(n))$ .
  12. more generally,

    \begin{displaymath} % latex2html id marker 253d_m(x):= \left\{ \begin{array}{l... ...xtrm{if } x =m, \ 0 & \textrm{otherwise.} \end{array}\right. \end{displaymath}
    is primitive recursive, for it is $d_0(\operatorname{diff}(x,\operatorname{const}_m(x))$ .
  13. even more generally,

    \begin{displaymath} % latex2html id marker 255d_S(x):= \left\{ \begin{array}{l... ...rm{if } x\in S, \ 0 & \textrm{otherwise.} \end{array}\right. \end{displaymath}
    where $S=\lbrace a_1,\ldots,a_m\rbrace$ , is primitive recursive, for it is $d_{a_1}+\cdots +d_{a_m}$ .
  14. \begin{displaymath} % latex2html id marker 257\operatorname{sgn}(x):= \left\{ ... ...xtrm{if } x =0, \ 1 & \textrm{otherwise.} \end{array}\right. \end{displaymath}
    which is just $\operatorname{sub}(\operatorname{const}_1(x),d_0(x))$ .
  15. \begin{displaymath} % latex2html id marker 259\operatorname{rem}(x,y):= \left\... ... x\!\!\!\!\!\mod\! y & \textrm{otherwise,} \end{array}\right. \end{displaymath}
    where $x\!\!\!\mod\! y$ is the remainder of $x\div y$ . Suppose $y\ne 0$ . Then $0\!\!\!\mod\! y=0$ . In addition,

    \begin{displaymath} % latex2html id marker 261(n+1)\!\!\!\!\mod\! y= \left\{ \... ... s(n\!\!\!\!\mod\! y) & \textrm{otherwise,} \end{array}\right. \end{displaymath}
    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$ .
  16. \begin{displaymath} % latex2html id marker 263q(x,y)= \left\{ \begin{array}{ll... ...rm{if } y \ne 0 \ 0 & \textrm{otherwise.} \end{array}\right. \end{displaymath}
    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

    \begin{displaymath} % latex2html id marker 265q(n+1,y)= \left\{ \begin{array}{... ...,y)+1 = y, \ q(n,y) & \textrm{otherwise.} \end{array}\right. \end{displaymath}
    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)

View style:

See Also: examples of primitive recursive predicates


This object's parent.

Attachments:
more examples of primitive recursive functions (Example) by CWoo
Log in to rate this entry.
(view current ratings)

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 MSC03D20 (Mathematical logic and foundations :: Computability and recursion theory :: Recursive functions and relations, subrecursive hierarchies)

Pending Errata and Addenda
None.
Discussion
Style: Expand: Order:
forum policy

No messages.

Interact
post | correct | update request | add example | add (any)