Mathwords logoMathwords

Ackermann Function — Definition, Formula & Example

The Ackermann function is a two-input function on whole numbers, defined by three short recursive rules. Every value can be computed in finitely many steps, but the outputs grow faster than any function you can build from ordinary bounded loops.

The Ackermann (Ackermann–Péter) function A:N×N→NA:\mathbb{N}\times\mathbb{N}\to\mathbb{N} is defined by A(0,n)=n+1A(0,n)=n+1, A(m,0)=A(m−1,1)A(m,0)=A(m-1,1) for m>0m>0, and A(m,n)=A(m−1,A(m,n−1))A(m,n)=A(m-1,A(m,n-1)) for m,n>0m,n>0. It is total and computable, because each call reduces the pair (m,n)(m,n) in lexicographic order. It is not primitive recursive: for every primitive recursive f:N→Nf:\mathbb{N}\to\mathbb{N} there is an mm with f(n)<A(m,n)f(n)<A(m,n) for all nn.

Key Formula

A(m,n)={n+1if m=0A(m−1, 1)if m>0, n=0A(m−1, A(m, n−1))if m>0, n>0A(m,n)=\begin{cases} n+1 & \text{if } m=0 \\ A(m-1,\,1) & \text{if } m>0,\ n=0 \\ A\big(m-1,\,A(m,\,n-1)\big) & \text{if } m>0,\ n>0 \end{cases}
Where:
  • mm = First argument, a natural number. It controls the growth level, so from row 3 on, each row grows far faster than the one before (rows 0 to 2 are linear: n+1n+1, n+2n+2, 2n+32n+3).
  • nn = Second argument, a natural number. It sets the position within row m.
  • A(m,n)A(m,n) = The natural-number output.

Worked Example

Problem: Use only the three defining rules to compute A(2,1)A(2,1).
Step 1: Work out row m=1m=1 first. Rule 2 gives the starting value. Rule 3 gives A(1,n)=A(0,A(1,n−1))=A(1,n−1)+1A(1,n)=A(0,A(1,n-1))=A(1,n-1)+1, so each step adds 1.
A(1,0)=A(0,1)=2,A(1,n)=n+2A(1,0)=A(0,1)=2, \qquad A(1,n)=n+2
Step 2: Find the inner value A(2,0)A(2,0) with rule 2, then use the row-1 pattern.
A(2,0)=A(1,1)=1+2=3A(2,0)=A(1,1)=1+2=3
Step 3: Apply rule 3. The inner call is evaluated first, and its output becomes the second input of the outer call. This nesting is what makes the function grow so fast.
A(2,1)=A(1, A(2,0))=A(1,3)=3+2=5A(2,1)=A\big(1,\,A(2,0)\big)=A(1,3)=3+2=5
Answer: A(2,1)=5A(2,1)=5. Continuing this way gives the row patterns A(1,n)=n+2A(1,n)=n+2, A(2,n)=2n+3A(2,n)=2n+3, and A(3,n)=2n+3−3A(3,n)=2^{n+3}-3, so A(3,1)=13A(3,1)=13. Row 4 is a tower of 2s: A(4,1)=2222−3=65533A(4,1)=2^{2^{2^{2}}}-3=65533, and A(4,2)=265536−3A(4,2)=2^{65536}-3 has 19,729 digits.

Why It Matters

In a theory of computation or logic course, the Ackermann function is the standard proof that primitive recursion, meaning programs with only bounded for-loops, does not capture every computable function. Its inverse α(n)\alpha(n) appears in algorithms courses. The union-find data structure used in Kruskal's minimum spanning tree algorithm runs in O(m α(n))O(m\,\alpha(n)) time, where mm is the number of operations on nn elements, and α(n)≤4\alpha(n)\le 4 for any input size you could ever store.

Common Mistakes

Mistake: Concluding that the Ackermann function is not computable because it outgrows every primitive recursive function.
Correction: It is computable. A simple recursive program, or a loop with a stack, finds any value in finitely many steps. 'Not primitive recursive' only means you cannot compute it with bounded loops alone. Computable and primitive recursive are different classes, and the first is strictly larger.

Related Terms