Ackermann function
Information about Ackermann function
In recursion theory, the Ackermann function or Ackermann-Péter function is a simple example of a general recursive function that is not primitive recursive. The general recursive functions is also known as the computable functions. The set of primitive recursive functions is a subset of the set of general recursive functions. Ackermann's function is an example that shows that it is a strict subset.
It takes two natural numbers as arguments and yields another natural number, using the notation A(m,n). Its value grows rapidly; even for small inputs, for example A(4,2)[1] and A(4,3), the results are large numbers. These large numbers in the m=4 row can also be expressed using tetrations.
Ackermann originally considered a function A(m, n, p) of three variables, the p-fold iterated exponentiation of m with n, or m → n → p as expressed using the Conway chained arrow notation. When p = 1, this is mn, which is m multiplied by itself n times. When p = 2, it is the double exponentiation
, and with p > 2, it is a tower of exponents
with n levels, or m raised n times to the power m also written as nm, the tetration of m with n. We can continue to generalize this indefinitely as p becomes larger.
Ackermann proved that A is a recursive function, a function a computer with unbounded memory can calculate, but it is not a primitive recursive function, a class of functions including almost all familiar functions such as addition and factorial.
In On the Infinite, David Hilbert hypothesized that the Ackermann function was not primitively recursive, but it was Ackermann, Hilbert’s personal secretary and former student, who actually proved the hypothesis in his paper On Hilbert’s Construction of the Real Numbers. On the Infinite was Hilbert’s most important paper on the foundations of mathematics, serving as the heart of Hilbert's program to secure the foundation of transfinite numbers by basing them on finite methods.[3][4]
A similar function of only two variables was later defined by Rózsa Péter and Raphael Robinson; its definition is given below. The numbers, except in the first few rows, are three less than powers of two. For the exact relation between the two functions, see below.[5]
It may not be immediately obvious that the evaluation of these functions always terminates. The recursion is bounded because in each recursive application either m decreases, or m remains the same and n decreases. Each time that n reaches zero, m decreases, so m eventually reaches zero as well. (Expressed more technically, in each case the pair (m, n) decreases in the lexicographic order, which preserves the well-ordering of the non-negative integers.) However, when m decreases there is no upper bound on how much n can increase — and it will often increase greatly.
The Ackermann function can also be expressed nonrecursively using:
For small values of m like 1, 2, or 3, the Ackermann function grows relatively slowly with respect to n (at most exponentially). For m ≥ 4, however, it grows much more quickly; even A(4, 2) is about 2×1019728, and the decimal expansion of A(4, 3) is very large by any typical measure.
If we define the function f (n) = A(n, n), which increases both m and n at the same time, we have a function of one variable that dwarfs every primitive recursive function, including very fast-growing functions such as the exponential function, the factorial function, multi- and superfactorial functions, and even functions defined using Knuth's up-arrow notation (except when the indexed up-arrow is used).
This extreme growth can be exploited to show that f, which is obviously computable on a machine with infinite memory such as a Turing machine and so is a computable function, grows faster than any primitive recursive function and is therefore not primitive recursive. Though the Ackermann function is often used to debunk the hypothesis that all useful or simple functions are primitive recursive, one should not confuse the primitive recursive functions with those definable by primitive recursion (it is this latter class that is of interest to programming language theorists because programs written using only primitive recursion are guaranteed to terminate). In a category with exponentials, using the isomorphism
, the Ackermann function may be defined via primitive recursion over higher-order functionals as follows:
where Succ is the usual successor function and Iter is defined by primitive recursion as well:
Another interesting class of functions are the Busy beaver functions, which grow faster than any recursive function, and indeed it can be shown that if they could be evaluated in general, we could solve the halting problem so evaluation using an algorithm is impossible.
One interesting aspect of the Ackermann function is that the only arithmetic operations it ever uses are addition and subtraction of 1. Its properties come solely from the power of unlimited recursion. This also implies that its running time is at least proportional to its output, and so is also extremely huge. In actuality, for most cases the running time is far larger than the output; see below.
The numbers listed here in a recursive reference are very large and cannot be easily notated in some other form.
Despite the large values occurring in this early section of the table, some even larger numbers have been defined, such as Graham's number, which cannot be written with any small number of Knuth arrows. This number is constructed with a technique similar to applying the Ackermann function to itself recursively.
This is a repeat of the above table, but with the values replaced by the relevant expression from the function definition to show the pattern clearly:
in the following way:
To demonstrate how
's computation results many steps and in a large number:
We stop here because
is
which is a short expression that still represents a large number. According to the formula for A(3,n) in the table above, the plus and minus three cancel out and the end result uses
which is then, itself raised as a power of 2 and then 3 subtracted to obtain the final result, which is a vastly larger number yet.
This inverse appears in the time complexity of some algorithms, such as the disjoint-set data structure and Chazelle's algorithm for minimum spanning trees. Sometimes Ackermann's original function or other variations are used in these settings, but they all grow at similarly high rates. In particular, some modified functions simplify the expression by eliminating the −3 and similar terms.
A two-parameter variation of the inverse Ackermann function can be defined as follows:
Other studies might define an inverse function of one where m is set to a constant, such that the inverse applies to a particular row.[6]
This seminal paper was taken up by Brian Wichmann (co-author of the Whetstone benchmark) in a trilogy of papers written between 1975 and 1982.[7][8][9]
A more recent use of Ackermann's function as a compiler benchmark is in The Computer Language Shootout which compares the time required to evaluate this function for fixed arguments in many different programming language implementations.[10][11]
For example, a compiler which, in analyzing the computation of A(3, 30), is able to save intermediate values like the A(3, n) and A(2, n) in that calculation rather than recomputing them, can speed up computation of A(3, 30) by a factor of hundreds of thousands. Also, if A(2, n) is computed directly rather than as a recursive expansion of the form A(1, A(1, A(1,...A(1, 0)...))), this will save significant amounts of time. Computing A(1, n) takes linear time in n. Computing A(2, n) requires quadratic time, since it expands to O(n) nested calls to A(1, i) for various i. Computing A(3, n) requires time proportionate to 4n+1. The computation of A(3, 1) in the example above takes 16 (42) steps.
A(4, 2), which appears as a decimal expansion in several web pages, cannot possibly be computed by simple recursive application of the Ackermann function in any tractable amount of time. Instead, shortcut formulas such as A(3, n) = 8×2n−3 are used as an optimization to complete some of the recursive calls.
A practical method of computing functions similar to Ackermann's is to use memoization of intermediate results. A compiler could apply this technique to a function automatically using Donald Michie's "memo functions".[12]
In Scheme:
(define (ackermann m n) (cond ((= m 0) (+ 1 n)) ((= n 0) (ackermann (- m 1) 1)) ((> n 0) (ackermann (- m 1) (ackermann m (- n 1))))))
In Haskell:
ackermann 0 n = (n + 1) ackermann m 0 = ackermann (m-1) 1 ackermann m n = ackermann (m-1) (ackermann m (n-1))
In ML:
fun ackermann (0,n) = n + 1 | ackermann (m,0) = ackermann (m-1, 1) | ackermann (m,n) = ackermann (m-1, ackermann (m, n-1));
In Ocaml:
let rec ackermann = function (0, n) -> n + 1 | (m, 0) -> ackermann (m-1, 1) | (m, n) -> ackermann (m-1, ackermann (m, n-1))
In C:
int ackermann(int m, int n) { if (m == 0) return n+1; else if (m > 0 && n == 0) return ackermann(m-1, 1); else if (m > 0 && n > 0) return ackermann(m-1, ackermann(m, n-1)); }
In Python:
def ackermann(m, n): if m == 0: return n+1 elif m > 0 and n == 0: return ackermann(m-1, 1) elif m > 0 and n > 0: return ackermann(m-1, ackermann(m, n-1))
In Perl:
sub ackermann { my($m, $n) = @_; return $n+1 if $m == 0; return ackermann($m-1, 1) if $m > 0 && $n == 0; return ackermann($m-1, ackermann($m, $n-1)) if $m > 0 && $n > 0; }
In Ruby:
def ackermann(m,n) if m==0 n+1 elsif m > 0 && n==0 ackermann(m-1,1) elsif m > 0 && n > 0 ackermann(m-1,ackermann(m,n-1)) end end
In Java:
public static int ackermann(int m, int n) { if (m == 0) return n+1; else if (m > 0 && n == 0) return ackermann(m-1, 1); else return ackermann(m-1, ackermann(m, n-1)); }
In Turing:
function ackermann (m : int, n : int) : int if m = 0 then result n + 1 elsif m > 0 and n = 0 then result A (m - 1, 1) else result A (m - 1, A (m, n - 1)) end if end A
In MIPS assembly:
ackerman: #Hmm, if m == o just return 1 addi $v0, $a1, 1 #We set our return value to 1 beq $a0, $zero, end #and if a0 == 0 we end it! #oh, we're gonna make some function calls, get ready! addi $sp, -8 #Make the stack bigger for registes you'll use sw $ra, 0($sp) #Save $s- variables sw $s0, 4($sp) #Save $ra variables bne $a1, $zero, fatrec #run the following if n == 0 addi $a0, $a0, -1 #set first arg to m - 1 addi $a1, $zero, 1 #set the second arg to 1 jal ackerman j clean
fatrec: #recursing twice! add $s0, $a0, $zero addi $a1, $a1, -1 jal ackerman addi $a0, $s0, -1 add $a1, $v0, $zero jal ackerman clean: lw $s0, 4($sp) #Restore $s- variables lw $ra, 0($sp) #Restore $ra variables addi $sp, $sp, 8 #restore stack pointer end: jr $ra #Jump to where we came from
def Ackermann(m, n): stack = [] stack.append(m) stack.append(n) while len(stack) > 1: n = stack.pop() m = stack.pop()
if m == 0: stack.append(n + 1) elif n == 0: stack.append(m-1) stack.append(1) else: stack.append(m-1) stack.append(m) stack.append(n-1)
return stack.pop()
in the Knuth's up-arrow notation, or
For instance, the first three Ackermann numbers are
An attempt to express the fourth Ackermann number, 4
4, using iterated exponentiation as above would become extremely complicated. However, it can be expressed using tetration in three nested layers as shown below. Explanation: in the middle layer, there is a tower of tetration whose full length is
and the final result is the top layer of tetrated 4's whose full length equals the calculation of the middle layer. Note that by way of size comparison, the simple expression
already exceeds a googolplex, so the fourth Ackermann number is quite large.
It takes two natural numbers as arguments and yields another natural number, using the notation A(m,n). Its value grows rapidly; even for small inputs, for example A(4,2)[1] and A(4,3), the results are large numbers. These large numbers in the m=4 row can also be expressed using tetrations.
History
In the late 1920s, the mathematicians Gabriel Sudan and Wilhelm Ackermann, students of David Hilbert, were studying the foundations of computation. Sudan is credited with inventing the lesser-known Sudan function, the first published function that is recursive but not primitive recursive. Shortly afterwards and independently, in 1928, Ackermann published his own recursive but not primitive recursive function.[2]Ackermann originally considered a function A(m, n, p) of three variables, the p-fold iterated exponentiation of m with n, or m → n → p as expressed using the Conway chained arrow notation. When p = 1, this is mn, which is m multiplied by itself n times. When p = 2, it is the double exponentiation
, and with p > 2, it is a tower of exponents
with n levels, or m raised n times to the power m also written as nm, the tetration of m with n. We can continue to generalize this indefinitely as p becomes larger.
Ackermann proved that A is a recursive function, a function a computer with unbounded memory can calculate, but it is not a primitive recursive function, a class of functions including almost all familiar functions such as addition and factorial.
In On the Infinite, David Hilbert hypothesized that the Ackermann function was not primitively recursive, but it was Ackermann, Hilbert’s personal secretary and former student, who actually proved the hypothesis in his paper On Hilbert’s Construction of the Real Numbers. On the Infinite was Hilbert’s most important paper on the foundations of mathematics, serving as the heart of Hilbert's program to secure the foundation of transfinite numbers by basing them on finite methods.[3][4]
A similar function of only two variables was later defined by Rózsa Péter and Raphael Robinson; its definition is given below. The numbers, except in the first few rows, are three less than powers of two. For the exact relation between the two functions, see below.[5]
Definition and properties
The Ackermann function is defined recursively for non-negative integers m and n as follows (this presentation is due to Rózsa Péter):
It may not be immediately obvious that the evaluation of these functions always terminates. The recursion is bounded because in each recursive application either m decreases, or m remains the same and n decreases. Each time that n reaches zero, m decreases, so m eventually reaches zero as well. (Expressed more technically, in each case the pair (m, n) decreases in the lexicographic order, which preserves the well-ordering of the non-negative integers.) However, when m decreases there is no upper bound on how much n can increase — and it will often increase greatly.
The Ackermann function can also be expressed nonrecursively using:
- Conway chained arrow notation:
- :A(m, n) = (2 → (n+3) → (m − 2)) − 3 for m > 2
- hence
- :2 → n → m = A(m+2,n-3) + 3 for n>2
- (n=1 and n=2 would correspond with A(m,−2) = −1 and A(m,−1) = 1, which could logically be added.)
- :A(m, n) = hyper(2, m, n + 3) − 3
- the indexed version of Knuth's up-arrow notation:
- :A(m, n) =

- The part of the definition A(m, 0) = A(m-1, 1) corresponds to
.
For small values of m like 1, 2, or 3, the Ackermann function grows relatively slowly with respect to n (at most exponentially). For m ≥ 4, however, it grows much more quickly; even A(4, 2) is about 2×1019728, and the decimal expansion of A(4, 3) is very large by any typical measure.
If we define the function f (n) = A(n, n), which increases both m and n at the same time, we have a function of one variable that dwarfs every primitive recursive function, including very fast-growing functions such as the exponential function, the factorial function, multi- and superfactorial functions, and even functions defined using Knuth's up-arrow notation (except when the indexed up-arrow is used).
This extreme growth can be exploited to show that f, which is obviously computable on a machine with infinite memory such as a Turing machine and so is a computable function, grows faster than any primitive recursive function and is therefore not primitive recursive. Though the Ackermann function is often used to debunk the hypothesis that all useful or simple functions are primitive recursive, one should not confuse the primitive recursive functions with those definable by primitive recursion (it is this latter class that is of interest to programming language theorists because programs written using only primitive recursion are guaranteed to terminate). In a category with exponentials, using the isomorphism
, the Ackermann function may be defined via primitive recursion over higher-order functionals as follows:
where Succ is the usual successor function and Iter is defined by primitive recursion as well:
Another interesting class of functions are the Busy beaver functions, which grow faster than any recursive function, and indeed it can be shown that if they could be evaluated in general, we could solve the halting problem so evaluation using an algorithm is impossible.
One interesting aspect of the Ackermann function is that the only arithmetic operations it ever uses are addition and subtraction of 1. Its properties come solely from the power of unlimited recursion. This also implies that its running time is at least proportional to its output, and so is also extremely huge. In actuality, for most cases the running time is far larger than the output; see below.
Table of values
Computing the Ackermann function can be restated in terms of an infinite table. We place the natural numbers along the top row. To determine a number in the table, take the number immediately to the left, then look up the required number in the previous row, at the position given by the number just taken. If there is no number to its left, simply look at column 1 in the previous row. Here is a small upper-left portion of the table:| m\n | 0 | 1 | 2 | 3 | 4 | n |
|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 3 | 4 | 5 | ![]() |
| 1 | 2 | 3 | 4 | 5 | 6 | ![]() |
| 2 | 3 | 5 | 7 | 9 | 11 | ![]() |
| 3 | 5 | 13 | 29 | 61 | 125 | ![]() |
| 4 | 13 | 65533 | 265536 − 3 | ![]() | A(3, A(4, 3)) | ![]() |
| 5 | 65533 | A(4, 65533) | A(4, A(5, 1)) | A(4, A(5, 2)) | A(4, A(5, 3)) | A(4, A(5, n-1)) |
| 6 | A(5, 1) | A(5, A(6, 0)) | A(5, A(6, 1)) | A(5, A(6, 2)) | A(5, A(6, 3)) | A(5, A(6, n-1)) |
The numbers listed here in a recursive reference are very large and cannot be easily notated in some other form.
Despite the large values occurring in this early section of the table, some even larger numbers have been defined, such as Graham's number, which cannot be written with any small number of Knuth arrows. This number is constructed with a technique similar to applying the Ackermann function to itself recursively.
This is a repeat of the above table, but with the values replaced by the relevant expression from the function definition to show the pattern clearly:
| m\n | 0 | 1 | 2 | 3 | 4 | n |
|---|---|---|---|---|---|---|
| 0 | 0+1 | 1+1 | 2+1 | 3+1 | 4+1 | ![]() |
| 1 | A(0,1) | A(0,A(1,0)) | A(0,(A(1,1)) | A(0,(A(1,2)) | A(0,(A(1,3)) | ![]() |
| 2 | A(1,1) | A(1,(A(2,0)) | A(1,(A(2,1)) | A(1,(A(2,2)) | A(1,(A(2,3)) | ![]() |
| 3 | A(2,1) | A(2,(A(3,0)) | A(2,(A(3,1)) | A(2,(A(3,2)) | A(2,(A(3,3)) | ![]() |
| 4 | A(3,1) | A(3,(A(4,0)) | A(3,(A(4,1)) | A(3,(A(4,2)) | A(3,(A(4,3)) |
![]() |
| 5 | A(4,1) | A(4,(A(5,0)) | A(4,(A(5,1)) | A(4,(A(5,2)) | A(4,(A(5,3)) | A(4, A(5, n-1)) |
| 6 | A(5,1) | A(5,(A(6,0)) | A(5,(A(6,1)) | A(5,(A(6,2)) | A(5,(A(6,3)) | A(5, A(6, n-1)) |
Expansion
To see how the Ackermann function grows so quickly, it helps to expand out some simple expressions using the rules in the original definition. For example, we can fully evaluate
in the following way:
To demonstrate how
's computation results many steps and in a large number:
We stop here because
is
which is a short expression that still represents a large number. According to the formula for A(3,n) in the table above, the plus and minus three cancel out and the end result uses
which is then, itself raised as a power of 2 and then 3 subtracted to obtain the final result, which is a vastly larger number yet.
Inverse
Since the function f (n) = A(n, n) considered above grows very rapidly, its inverse function, f−1, grows very slowly. This inverse Ackermann function f−1 is usually denoted by α. In fact, α(n) is less than 5 for any conceivable input size n, since A(4, 4) is a large number. "For all practical purposes", α(n) can be regarded as being a constant.This inverse appears in the time complexity of some algorithms, such as the disjoint-set data structure and Chazelle's algorithm for minimum spanning trees. Sometimes Ackermann's original function or other variations are used in these settings, but they all grow at similarly high rates. In particular, some modified functions simplify the expression by eliminating the −3 and similar terms.
A two-parameter variation of the inverse Ackermann function can be defined as follows:
Other studies might define an inverse function of one where m is set to a constant, such that the inverse applies to a particular row.[6]
Use as benchmark
The Ackermann function, due to its definition in terms of extremely deep recursion, can be used as a benchmark of a compiler's ability to optimize recursion. The first use of Ackermann's function in this way was by Y. Sundblad, The Ackermann function. A Theoretical, computational and formula manipulative study. (BIT 11 (1971), 107119).This seminal paper was taken up by Brian Wichmann (co-author of the Whetstone benchmark) in a trilogy of papers written between 1975 and 1982.[7][8][9]
A more recent use of Ackermann's function as a compiler benchmark is in The Computer Language Shootout which compares the time required to evaluate this function for fixed arguments in many different programming language implementations.[10][11]
For example, a compiler which, in analyzing the computation of A(3, 30), is able to save intermediate values like the A(3, n) and A(2, n) in that calculation rather than recomputing them, can speed up computation of A(3, 30) by a factor of hundreds of thousands. Also, if A(2, n) is computed directly rather than as a recursive expansion of the form A(1, A(1, A(1,...A(1, 0)...))), this will save significant amounts of time. Computing A(1, n) takes linear time in n. Computing A(2, n) requires quadratic time, since it expands to O(n) nested calls to A(1, i) for various i. Computing A(3, n) requires time proportionate to 4n+1. The computation of A(3, 1) in the example above takes 16 (42) steps.
A(4, 2), which appears as a decimal expansion in several web pages, cannot possibly be computed by simple recursive application of the Ackermann function in any tractable amount of time. Instead, shortcut formulas such as A(3, n) = 8×2n−3 are used as an optimization to complete some of the recursive calls.
A practical method of computing functions similar to Ackermann's is to use memoization of intermediate results. A compiler could apply this technique to a function automatically using Donald Michie's "memo functions".[12]
Implementations
The first implementation in a programming language was in Fortran in 1964, see H. Gordon Rice[13], Recursion and iteration, Commun. ACM, 8(2), 1965, pp. 114--115.)In Scheme:
(define (ackermann m n) (cond ((= m 0) (+ 1 n)) ((= n 0) (ackermann (- m 1) 1)) ((> n 0) (ackermann (- m 1) (ackermann m (- n 1))))))
In Haskell:
ackermann 0 n = (n + 1) ackermann m 0 = ackermann (m-1) 1 ackermann m n = ackermann (m-1) (ackermann m (n-1))
In ML:
fun ackermann (0,n) = n + 1 | ackermann (m,0) = ackermann (m-1, 1) | ackermann (m,n) = ackermann (m-1, ackermann (m, n-1));
In Ocaml:
let rec ackermann = function (0, n) -> n + 1 | (m, 0) -> ackermann (m-1, 1) | (m, n) -> ackermann (m-1, ackermann (m, n-1))
In C:
int ackermann(int m, int n) { if (m == 0) return n+1; else if (m > 0 && n == 0) return ackermann(m-1, 1); else if (m > 0 && n > 0) return ackermann(m-1, ackermann(m, n-1)); }
In Python:
def ackermann(m, n): if m == 0: return n+1 elif m > 0 and n == 0: return ackermann(m-1, 1) elif m > 0 and n > 0: return ackermann(m-1, ackermann(m, n-1))
In Perl:
sub ackermann { my($m, $n) = @_; return $n+1 if $m == 0; return ackermann($m-1, 1) if $m > 0 && $n == 0; return ackermann($m-1, ackermann($m, $n-1)) if $m > 0 && $n > 0; }
In Ruby:
def ackermann(m,n) if m==0 n+1 elsif m > 0 && n==0 ackermann(m-1,1) elsif m > 0 && n > 0 ackermann(m-1,ackermann(m,n-1)) end end
In Java:
public static int ackermann(int m, int n) { if (m == 0) return n+1; else if (m > 0 && n == 0) return ackermann(m-1, 1); else return ackermann(m-1, ackermann(m, n-1)); }
In Turing:
function ackermann (m : int, n : int) : int if m = 0 then result n + 1 elsif m > 0 and n = 0 then result A (m - 1, 1) else result A (m - 1, A (m, n - 1)) end if end A
In MIPS assembly:
ackerman: #Hmm, if m == o just return 1 addi $v0, $a1, 1 #We set our return value to 1 beq $a0, $zero, end #and if a0 == 0 we end it! #oh, we're gonna make some function calls, get ready! addi $sp, -8 #Make the stack bigger for registes you'll use sw $ra, 0($sp) #Save $s- variables sw $s0, 4($sp) #Save $ra variables bne $a1, $zero, fatrec #run the following if n == 0 addi $a0, $a0, -1 #set first arg to m - 1 addi $a1, $zero, 1 #set the second arg to 1 jal ackerman j clean
fatrec: #recursing twice! add $s0, $a0, $zero addi $a1, $a1, -1 jal ackerman addi $a0, $s0, -1 add $a1, $v0, $zero jal ackerman clean: lw $s0, 4($sp) #Restore $s- variables lw $ra, 0($sp) #Restore $ra variables addi $sp, $sp, 8 #restore stack pointer end: jr $ra #Jump to where we came from
Non-Recursive Ackermann in Python
This algorithm uses a software stack much like Reverse Polish notationdef Ackermann(m, n): stack = [] stack.append(m) stack.append(n) while len(stack) > 1: n = stack.pop() m = stack.pop()
if m == 0: stack.append(n + 1) elif n == 0: stack.append(m-1) stack.append(1) else: stack.append(m-1) stack.append(m) stack.append(n-1)
return stack.pop()
Non-Recursive Ackermann in C++
int Ackermann( int n, int m) { stack stk; int rt,ff,x=NULL,y=NULL,z=NULL; bool exit = false; do{ while( n != 0 ) { if( m == 0 ){ rt = 1; stk.push( rt ); stk.push( n ); stk.push( m ); stk.push( x ); stk.push( y ); stk.push( z ); m = 1; n = n - 1;} else{ rt = 2; stk.push( rt ); stk.push( n ); stk.push( m ); stk.push( x ); stk.push( y ); stk.push( z ); m = m - 1;} } ff = m + 1; exit = false; while( stk.tos > -1 && exit == false ) { z = stk.pop(); y = stk.pop(); x = stk.pop(); m = stk.pop(); n = stk.pop(); rt = stk.pop(); if( rt == 3 )z = ff; else if( rt == 2 ){ y = ff; rt = 3; stk.push( rt ); stk.push( n ); stk.push( m ); stk.push( x ); stk.push( y ); stk.push( z ); m = y; n = n - 1; exit = true;} } }while( stk.tos > -1 ); return ff; }And here is the algorithm of above code:
Ackermann numbers
Related to the Ackermann function but in fact different are the Ackermann numbers, a sequence where the nth term equals:in the Knuth's up-arrow notation, or
For instance, the first three Ackermann numbers are
- *1
1,
- *2
2
- *3
3
- *1 = 1
- *22 = 4
- *

An attempt to express the fourth Ackermann number, 4
4, using iterated exponentiation as above would become extremely complicated. However, it can be expressed using tetration in three nested layers as shown below. Explanation: in the middle layer, there is a tower of tetration whose full length is
and the final result is the top layer of tetrated 4's whose full length equals the calculation of the middle layer. Note that by way of size comparison, the simple expression
already exceeds a googolplex, so the fourth Ackermann number is quite large.
In popular culture
Randall Munroe has mentioned the Ackermann function in his popular web-comic xkcd.[15] In the comic, Munroe makes reference to the Ackermann function with Graham's Number as the arguments. At the time, he considered this to be the largest number ever concisely defined and named it "The xkcd number".[16]See also
Notes and references
1. ^ Decimal expansion of A(4,2) contains 19729 decimal digits
2. ^ Cristian Calude, Solomon Marcus and Ionel Tevy (November 1979). "The first example of a recursive function which is not primitive recursive". Historia Math. 6 (4): 380–84. Summarized in Bill Dubuque (1997-09-12). "[news://y8zoh5yn377.fsf@berne.ai.mit.edu Ackermann vs. Sudan]". [news://sci.logic sci.logic]. (Google Groups). Retrieved on 2006-06-13.
3. ^ Wilhelm Ackermann (1928). "Zum Hilbertschen Aufbau der reellen Zahlen". Mathematische Annalen 99: 118–133.
4. ^ von Heijenoort. From Frege To Gödel, 1967.
5. ^ Raphael M. Robinson (1948). "Recursion and Double Recursion". Bulletin of the American Mathematical Society 54: 987–93.
6. ^ An inverse-Ackermann style lower bound for the online minimum spanning tree verification problem November 2002
7. ^ Ackermann's Function: A Study In The Efficiency Of Calling Procedures (1975).
8. ^ How to Call Procedures, or Second Thoughts on Ackermann's Function (1977).
9. ^ Latest results from the procedure calling test, Ackermann's function (1982).
10. ^ Gentoo: Intel Pentium 4 Computer Language Shootout (2006). Retrieved on 2006-06-13.
11. ^ Benchmarks XGC, May 11, 2005
12. ^ Example: Explicit memo function version of Ackermann's function implemented in PL/SQL
13. ^ The author of Rice's theorem !
14. ^ Ackermann Number
15. ^ "What xkcd Means". Retrieved on 2007-06-25.
16. ^ "The Clarkkkkson vs. the xkcd Number". Retrieved on 2007-06-25.
2. ^ Cristian Calude, Solomon Marcus and Ionel Tevy (November 1979). "The first example of a recursive function which is not primitive recursive". Historia Math. 6 (4): 380–84. Summarized in Bill Dubuque (1997-09-12). "[news://y8zoh5yn377.fsf@berne.ai.mit.edu Ackermann vs. Sudan]". [news://sci.logic sci.logic]. (Google Groups). Retrieved on 2006-06-13.
3. ^ Wilhelm Ackermann (1928). "Zum Hilbertschen Aufbau der reellen Zahlen". Mathematische Annalen 99: 118–133.
4. ^ von Heijenoort. From Frege To Gödel, 1967.
5. ^ Raphael M. Robinson (1948). "Recursion and Double Recursion". Bulletin of the American Mathematical Society 54: 987–93.
6. ^ An inverse-Ackermann style lower bound for the online minimum spanning tree verification problem November 2002
7. ^ Ackermann's Function: A Study In The Efficiency Of Calling Procedures (1975).
8. ^ How to Call Procedures, or Second Thoughts on Ackermann's Function (1977).
9. ^ Latest results from the procedure calling test, Ackermann's function (1982).
10. ^ Gentoo: Intel Pentium 4 Computer Language Shootout (2006). Retrieved on 2006-06-13.
11. ^ Benchmarks XGC, May 11, 2005
12. ^ Example: Explicit memo function version of Ackermann's function implemented in PL/SQL
13. ^ The author of Rice's theorem !
14. ^ Ackermann Number
15. ^ "What xkcd Means". Retrieved on 2007-06-25.
16. ^ "The Clarkkkkson vs. the xkcd Number". Retrieved on 2007-06-25.
External links
- Eric W. Weisstein, Ackermann function at MathWorld.
- Paul E. Black, Ackermann's function at the NIST Dictionary of Algorithms and Data Structures.
- Scott Aaronson, Who can name the biggest number? (1999)
- Ackermann function's. Includes a table of some values.
- Hyper-operations: Ackermann's Function and New Arithmetical Operation
- Robert Munafo's Versions of Ackermann's Function describes several variations on the definition of A.
- Gabriel Nivasch, Inverse Ackermann without pain on the inverse Ackermann function.
- Raimund Seidel, Understanding the inverse Ackermann function (PDF presentation).
Recursion theory, also called computability theory, is a branch of mathematical logic that originated in the 1930s with the study of computable functions and Turing degrees. The field has grown to include the study of generalized computability and definability.
..... Click the link for more information.
..... Click the link for more information.
The primitive recursive functions are defined using primitive recursion and composition as central operations and are a strict subset of the recursive functions (recursive functions are also known as the computable functions).
..... Click the link for more information.
..... Click the link for more information.
Computable functions (or Turing-computable functions) are the basic objects of study in computability theory. They make precise the intuitive notion of algorithm. Computable functions can be used to discuss computability without referring to any concrete model of computation
..... Click the link for more information.
..... Click the link for more information.
subset of a set B if A is "contained" inside B. Notice that A and B may coincide. The relationship of one set being a subset of another is called inclusion or containment.
..... Click the link for more information.
..... Click the link for more information.
subset of a set B if A is "contained" inside B. Notice that A and B may coincide. The relationship of one set being a subset of another is called inclusion or containment.
..... Click the link for more information.
..... Click the link for more information.
In mathematics, a natural number can mean either an element of the set (i.e the positive integers or the counting numbers) or an element of the set (i.e. the non-negative integers).
..... Click the link for more information.
..... Click the link for more information.
Large numbers are numbers that are significantly larger than those ordinarily used in everyday life, for instance in simple counting or in monetary transactions. The term typically refers to large positive integers, or more generally, large positive real numbers, but it may also be
..... Click the link for more information.
..... Click the link for more information.
Tetration (also exponential map, hyperpower, power tower, super-exponentiation, and hyper4) is iterated exponentiation, the first hyper operator after exponentiation.
..... Click the link for more information.
..... Click the link for more information.
Gabriel Sudan (born c. 1899) was a Romanian mathematician, known for the Sudan function (1927), an important example in the theory of computation, similar to the Ackermann function (1928).
Gabriel Sudan received his Ph.D.
..... Click the link for more information.
Gabriel Sudan received his Ph.D.
..... Click the link for more information.
Wilhelm Friedrich Ackermann (March 29, 1896, Herscheid municipality, Germany – December 24, 1962 Lüdenscheid, Germany ) was a German mathematician best known for the Ackermann function, an important example in the theory of computation.
Ackermann was awarded the Ph.D.
..... Click the link for more information.
Ackermann was awarded the Ph.D.
..... Click the link for more information.
David Hilbert
David Hilbert (1912)
Born January 23 1862
Wehlau (Welawa), Province of Prussia
..... Click the link for more information.
David Hilbert (1912)
Born January 23 1862
Wehlau (Welawa), Province of Prussia
..... Click the link for more information.
In the theory of computation, the Sudan function is an example of a function that is recursive, but not primitive recursive. This is also true of the better-known Ackermann function. The Sudan function was the first function having this property to be published.
..... Click the link for more information.
..... Click the link for more information.
Recursive may refer to:
..... Click the link for more information.
- Recursion
- Recursively enumerable language
- Recursively enumerable set
- Recursive filter
- Recursive function
- Recursive language
- Recursive acronym
- Recursive set
- Primitive recursive function
..... Click the link for more information.
The primitive recursive functions are defined using primitive recursion and composition as central operations and are a strict subset of the recursive functions (recursive functions are also known as the computable functions).
..... Click the link for more information.
..... Click the link for more information.
Conway chained arrow notation, created by mathematician John Horton Conway, is a means of expressing certain extremely large numbers. It is simply a finite sequence of positive integers separated by rightward arrows, e.g. 2→3→4→5→6.
..... Click the link for more information.
..... Click the link for more information.
Tetration (also exponential map, hyperpower, power tower, super-exponentiation, and hyper4) is iterated exponentiation, the first hyper operator after exponentiation.
..... Click the link for more information.
..... Click the link for more information.
The primitive recursive functions are defined using primitive recursion and composition as central operations and are a strict subset of the recursive functions (recursive functions are also known as the computable functions).
..... Click the link for more information.
..... Click the link for more information.
factorial of a non-negative integer is the product of all positive integers less than or equal to . For example,
..... Click the link for more information.
- and
..... Click the link for more information.
Hilbert's program, formulated by German mathematician David Hilbert in the 1920s, was to formalize all existing theories to a finite, complete set of axioms, and provide a proof that these axioms were consistent.
..... Click the link for more information.
..... Click the link for more information.
Rózsa Péter (orig.: Politzer), (February 17, 1905–February 16, 1977) was a Hungarian mathematician. She is best known for her work with recursion theory.
Péter was born in Budapest, Hungary, as Rósa Politzer.
..... Click the link for more information.
Péter was born in Budapest, Hungary, as Rósa Politzer.
..... Click the link for more information.
Raphael Mitchel Robinson (November 2 1911, National City California - January 27 1995. Berkeley California) was an American mathematician.
Born in National City, California, Robinson was the youngest of four children of a lawyer and a teacher.
..... Click the link for more information.
Born in National City, California, Robinson was the youngest of four children of a lawyer and a teacher.
..... Click the link for more information.
Recursion, in mathematics and computer science, is a method of defining functions in which the function being defined is applied within its own definition. The term is also used more generally to describe a process of repeating objects in a self-similar way.
..... Click the link for more information.
..... Click the link for more information.
Rózsa Péter (orig.: Politzer), (February 17, 1905–February 16, 1977) was a Hungarian mathematician. She is best known for her work with recursion theory.
Péter was born in Budapest, Hungary, as Rósa Politzer.
..... Click the link for more information.
Péter was born in Budapest, Hungary, as Rósa Politzer.
..... Click the link for more information.
In mathematics, the lexicographic or lexicographical order, (also known as dictionary order, alphabetic order or lexicographic(al) product), is a natural order structure of the Cartesian product of two ordered sets.
..... Click the link for more information.
..... Click the link for more information.
In mathematics, a well-order relation (or well-ordering) on a set S is a total order on S with the property that every non-empty subset of S has a least element in this ordering. Equivalently, a well-ordering is a well-founded total order.
..... Click the link for more information.
..... Click the link for more information.
Conway chained arrow notation, created by mathematician John Horton Conway, is a means of expressing certain extremely large numbers. It is simply a finite sequence of positive integers separated by rightward arrows, e.g. 2→3→4→5→6.
..... Click the link for more information.
..... Click the link for more information.
The hyper operators forming the hypern family are as follows:
(See Knuth's up-arrow notation and Conway chained arrow notation.
..... Click the link for more information.
- hypern (a, b) =
(See Knuth's up-arrow notation and Conway chained arrow notation.
..... Click the link for more information.
In mathematics, Knuth's up-arrow notation is a notation for very large integers introduced by Donald Knuth in 1976. The idea is based on iterated exponentiation in much the same way that exponentiation is iterated multiplication, and multiplication is iterated addition.
..... Click the link for more information.
..... Click the link for more information.
In mathematics, exponential growth (or geometric growth) occurs when the growth rate of a function is always proportional to the function's current size. Such growth is said to follow an exponential law (but see also Malthusian growth model).
..... Click the link for more information.
..... Click the link for more information.
The exponential function is one of the most important functions in mathematics. The application of this function to a value x is written as exp(x).
..... Click the link for more information.
..... Click the link for more information.
This article is copied from an article on Wikipedia.org - the free encyclopedia created and edited by online user community. The text was not checked or edited by anyone on our staff. Although the vast majority of the wikipedia encyclopedia articles provide accurate and timely information please do not assume the accuracy of any particular article. This article is distributed under the terms of GNU Free Documentation License.










