On this page
Wilhelm Ackermann published his function in 1928 in Mathematische Annalen (Ackermann 1928, Zum Hilbertschen Aufbau der reellen Zahlen). It is a counterexample to a belief of the early 1900s that every computable function is primitive recursive, that is, buildable from simple counted loops (MathWorld).
What is the Ackermann function?
The version almost all authors now use is the two-argument form developed by Rózsa Péter (1935) and Raphael Robinson (1948), as the Wikipedia article on the Ackermann function records. For non-negative integers m and n:
A(0, n) = n + 1
A(m, 0) = A(m − 1, 1) when m > 0
A(m, n) = A(m − 1, A(m, n − 1)) when m > 0 and n > 0
Every call either lowers m, or keeps m and lowers n, so the recursion always stops. That makes A total and computable: it has a value for every input, and a program can find it.
Why is the Ackermann function not primitive recursive?
Primitive recursive functions are the ones you can build from zero, adding one, and loops whose number of repetitions is fixed before the loop starts (a "for" loop, never an open-ended "while" loop). The Ackermann function is a total computable function that is not primitive recursive (Wikipedia). The reason is growth: A eventually outgrows every primitive recursive function, so no fixed nest of for-loops can keep up with it. MathWorld calls it "the simplest example of a well-defined total function which is computable but not primitive recursive" (MathWorld).
How do you evaluate A(1, 2) and A(2, 1) by hand?
Write every step and always expand the innermost call first. For A(1, 2):
A(1, 2) = A(0, A(1, 1)) by rule 3
A(1, 1) = A(0, A(1, 0)) by rule 3
A(1, 0) = A(0, 1) = 2 by rules 2 and 1
So A(1, 1) = A(0, 2) = 3
So A(1, 2) = A(0, 3) = 4
For A(2, 1):
A(2, 1) = A(1, A(2, 0)) by rule 3
A(2, 0) = A(1, 1) = 3 by rule 2 and the work above
So A(2, 1) = A(1, 3) = A(0, A(1, 2)) = A(0, 4) = 5
Notice that A(2, 1) needed A(1, 2) along the way. That reuse is why a program that stores values it has already found (memoisation) runs much faster than plain recursion.
What are the closed forms for m ≤ 3?
For small m the function has simple formulas, listed by both MathWorld and Wikipedia:
A(0, n) = n + 1
A(1, n) = n + 2
A(2, n) = 2n + 3
A(3, n) = 2^(n+3) − 3
Check them against the worked values: A(1, 2) = 2 + 2 = 4 and A(2, 1) = 2 + 3 = 5. Then A(3, 3) = 2^6 − 3 = 61. At m = 4, MathWorld gives a tower of 2s of height n + 3, minus 3, so A(4, 1) = 2^16 − 3 = 65,533. One step further, A(4, 2) = 2^65536 − 3, an integer with 19,729 decimal digits (Wikipedia). Our post on Big O notation and growth rates shows how fast one exponential already grows; here they are stacked.
Where does the inverse Ackermann function show up?
The inverse, written α(n), grows as slowly as A grows fast. In 1975 Robert Tarjan proved an O(m α(n)) time bound for m operations on the union-find (disjoint-set) forest with path compression, and showed the bound is tight (Tarjan 1975, Journal of the ACM; summarised in Wikipedia's disjoint-set article). That article notes the α(n) factor is 4 or less for any n that can actually be written in the physical universe. So in practice each operation costs about a constant.
To see the data structure itself, read our step-by-step guide to union-find disjoint sets with rank and path compression.
How should you practise the Ackermann function?
One sitting, five steps:
Write the three rules from memory.
Expand A(1, 2) and A(2, 1) on paper without looking.
Expand A(2, 2) and check it against 2 × 2 + 3 = 7.
Prove A(1, n) = n + 2 by induction on n, starting from A(1, 0) = 2 and using rule 3.
Code it with memoisation and compute A(3, 5); the closed form says 253. Then explain why A(4, 2) is out of reach.
If step 4 stalls, the Fermi Concept Library gives each concept in mathematics and computing its own lesson and its place in the map, so you can go back to induction first. For more practice, the Fermi Problem Library has worked problems with a step-by-step solver that explains the reasoning rather than printing an answer.
For what no program can compute at all, read why the halting problem is undecidable.



