# Ackermann function is total recursive

In this entry, we give a formal proof that the Ackermann function $A(x,y)$, given by

 $A(0,y)=y+1,\qquad A(x+1,0)=A(x,1),\qquad A(x+1,y+1)=A(x,A(x+1,y))$

is both a total function and a recursive function . Actually, the fact that $A$ is total is proved in this entry (http://planetmath.org/PropertiesOfAckermannFunction). It remains to show that $A$ is recursive.

Recall that the computation of $A(x,y)$, given $x,y$, can be thought of as an iterated operation performed on finite sequences of integers, starting with $x,y$ and ending with $z=A(x,y)$ (see this entry (http://planetmath.org/ComputingTheAckermannFunction)). It is this process we will utilize to prove that $A$ is recursive.

In the proof below, the following notations and definitions are used to simplify matters:

• if $s$ is the sequence $r_{1},\ldots,r_{m}$, then $E(s)$ or $\langle r_{1},\ldots,r_{m}\rangle$ denote the code number of $s$ given the encoding $E$;

• $\operatorname{lh}(n)$ is the length of the sequence whose code number is $n$;

• $(n)_{i}$ is the $i$-th number in the sequence whose code number is $n$;

• $(n)_{-i}$ is the $i$-th to the last number in the sequence whose code number is $n$ (so that $(n)_{-1}$ is the last number in the sequence whose code number is $n$);

• $\operatorname{red}(n)$ is the code number of the sequence obtained by deleting the last number of the sequence whose code number is $n$;

• $\operatorname{ext}(n,a)$ is the code number of the sequence obtained by appending $a$ to the end of the sequence whose code number is $n$.

If $E$ is a primitive recursive encoding, then each of the above function is primitive recursive. For example, $(n)_{-i}=(n)_{\operatorname{lh}(n)\dot{-}i+1}$.

###### Theorem 1.

$A$ is recursive.

###### Proof.

In this proof, the choice of encoding $E$ is the multiplicative encoding, for it is convenient and, more importantly, a primitive recursive encoding. Briefly,

 $E(r_{1},\ldots,r_{m})=p_{1}^{r_{1}+1}\cdots p_{m}^{r_{m}+1},$

where $p_{i}$ is the $i$-th prime number (so that $p_{1}=2$).

We know that computing $A(x,y)=z$ is basically a sequence of computations on finite sequences:

 $x,y\longrightarrow\cdots\longrightarrow z\longrightarrow z\longrightarrow\cdots$

Let $s(x,y,i)$ denote the sequence at step $i$, then the above sequence can be rewritten:

 $s(x,y,0)\longrightarrow s(x,y,1)\longrightarrow\cdots\longrightarrow s(x,y,k)\longrightarrow\cdots$

Define $f(x,y,i)=E(s(x,y,i))$. From this we see that

 $g(x,y)=\mu i[f(x,y,i)=f(x,y,i+1)].$

is the function that computes the smallest number of steps needed so that the code number becomes stationary. When the code number is decoded, we get the resulting value of $A(x,y)$:

 $A(x,y)=D(f(x,y,g(x,y))),$

where $D(m):=(m)_{-1}$, decodes $m$, and returns the last number in the sequence $s$ whose code number $E(s)$ is $m$.

Now the remaining task to show that $f$ is primitive recursive. First, note that

 $f(x,y,0)=\langle x,y\rangle=2^{x+1}3^{y+1}$

is primitive recursive. Next, we want to express

 $f(x,y,n+1)=h(f(x,y,n)),$

where $h$ is the function that changes the code number of the sequence $s(x,y,n)$ to the code number of the sequence $s(x,y,n+1)$. Once we obtain $h$ and show that $h$ is primitive recursive, then $f$ is primitive recursive, as it is defined by primitive recursion via primitive recursive functions $\langle x,y\rangle$ and $h$.

To find out what $h$ is, recall the four rules of constructing the next sequence from the current one givne in this this entry (http://planetmath.org/ComputingTheAckermannFunction). Let $n_{1}=E(s(x,y,k))$ and $n_{2}=E(s(x,y,k+1))$. We rewrite the four rules using the notations and definitions here:

1. 1.

if $\operatorname{lh}(n_{1})=1$, then $n_{2}=n_{1}$;

2. 2.

if $\operatorname{lh}(n_{1})>1$, and $(n_{1})_{-2}=0$, then $n_{2}=h_{1}(n_{1})$, where

 $h_{1}(n):=\operatorname{ext}(\operatorname{red}^{2}(n),(n)_{-1}+1);$
3. 3.

if $\operatorname{lh}(n_{1})>1$, and $(n_{1})_{-2}>0$ and $(n_{1})_{-1}=0$, then $n_{2}=h_{2}(n_{1})$, where

 $h_{2}(n):=\operatorname{ext}(\operatorname{ext}(\operatorname{red}^{2}(n),(n)_% {-2}-1),1);$

or

4. 4.

if $\operatorname{lh}(n_{1})>1$, and $(n_{1})_{-2}>0$ and $(n_{1})_{-1}>0$, then then $n_{2}=h_{3}(n_{1})$, where

 $h_{3}(n):=\operatorname{ext}(\operatorname{ext}(\operatorname{ext}(% \operatorname{red}^{2}(n),(n)_{-2}-1),(n)_{-2}),(n)_{-1}-1).$
1. 1.

$\Phi_{0}(n):=\operatorname{lh}(n)\leq 1$,

2. 2.

$\Phi_{1}(n):=\operatorname{lh}(n)>1\textrm{, and }(n)_{-2}=0$,

3. 3.

$\Phi_{2}(n):=\operatorname{lh}(n)>1\textrm{, and }(n)_{-2}>0\textrm{ and }(n)_% {-1}=0$,

4. 4.

$\Phi_{3}(n):=\operatorname{lh}(n)>1\textrm{, and }(n)_{-2}>0\textrm{ and }(n)_% {-1}>0$.

Then each $\Phi_{i}$ is primitive recursive, pairwise exclusive, and $\Phi_{0}\equiv\neg\Phi_{1}\wedge\neg\Phi_{2}\wedge\neg\Phi_{3}$. Now, define $h$ as follows:

 $h(n):=\left\{\begin{array}[]{ll}\operatorname{id}(n)&\textrm{if }\Phi_{0}(n),% \\ h_{1}(n)&\textrm{if }\Phi_{1}(n),\\ h_{2}(n)&\textrm{if }\Phi_{2}(n),\\ h_{3}(n)&\textrm{if }\Phi_{3}(n).\end{array}\right.$

Since $h$ is defined by cases, and each $h_{i}$ is primitive recursive, $h$ is also primitive recursive. ∎

Title Ackermann function is total recursive AckermannFunctionIsTotalRecursive 2013-03-22 19:07:53 2013-03-22 19:07:53 CWoo (3771) CWoo (3771) 15 CWoo (3771) Theorem msc 03D75 AckermannFunctionIsNotPrimitiveRecursive
{"ft_lang_label":"__label__en","ft_lang_prob":0.8548687,"math_prob":0.99998915,"size":3415,"snap":"2020-10-2020-16","text_gpt3_token_len":785,"char_repetition_ratio":0.1967165,"word_repetition_ratio":0.12776831,"special_character_ratio":0.23982431,"punctuation_ratio":0.15123457,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":1.0000085,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"im_url_duplicate_count":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-04-05T14:42:16Z\",\"WARC-Record-ID\":\"<urn:uuid:aa285a2d-f7ef-4d05-b930-98511350bcc7>\",\"Content-Length\":\"47269\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:5be68ee1-1303-46b0-8311-9d58193cfa3c>\",\"WARC-Concurrent-To\":\"<urn:uuid:77fb2cd4-06f6-4737-aed2-8e6fb1c8ddae>\",\"WARC-IP-Address\":\"129.97.206.129\",\"WARC-Target-URI\":\"https://planetmath.org/ackermannfunctionistotalrecursive\",\"WARC-Payload-Digest\":\"sha1:JXLIKARNKFKDCB7FCD6RIJVCBEJAG53U\",\"WARC-Block-Digest\":\"sha1:3L5AY57DIX7MWL2ZFX3YRBHGEOW45WIA\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-16/CC-MAIN-2020-16_segments_1585371604800.52_warc_CC-MAIN-20200405115129-20200405145629-00353.warc.gz\"}"}