Ackermann Function Calculator
Recursion
- The Ackermann function A(m, n) is defined by nested recursion: A(0, n) = n + 1, A(m, 0) = A(m - 1, 1), and A(m, n) = A(m - 1, A(m, n - 1)).
- Each fixed m collapses to a closed form; for m = 0 it is n + 1.
- Substituting n = 3 gives A(0, 3) = 4 - no recursion needs to be unfolded.
- Wilhelm Ackermann published the function in 1928 to give an explicit example of a computable function that is not primitive recursive; its growth outruns every simple loop hierarchy.
The Ackermann function is the standard exhibit for 'computable but not primitive recursive': a function defined by a three-line recursion whose values outgrow every loop-based growth pattern. Its first rows are tame - addition, multiplication, exponentiation - and then the floor drops out: A(4, 1) = 65,533, and A(4, 2) = 2^65,536 - 3, a number with 19,729 digits.
The definition: A(0, n) = n + 1; A(m, 0) = A(m - 1, 1); A(m, n) = A(m - 1, A(m, n - 1)). Each row is built by iterating the previous row, which is why closed forms exist per row: A(1, n) = n + 2, A(2, n) = 2n + 3, A(3, n) = 2^(n + 3) - 3, and A(4, n) is a power tower of 2s of height n + 3, minus 3.
This Ackermann function calculator evaluates the small cases by honest recursion and the larger ones by their closed forms, reporting the row's formula with each answer. Verified values: A(2, 3) = 9, A(3, 4) = 125, A(4, 1) = 65,533, with A(4, 0) = 13 as the tower's base.
Worked examples
A(2, 3)
(m = 2 · 3)
| Ackermann value A(2, 3) | 9 |
| closed form for m = 2 | 2n + 3 |
| one row down: A(1, 3) | 5 |
| one step along: A(2, 4) | 11 |
A(3, 4)
(m = 3 · 4)
| Ackermann value A(3, 4) | 125 |
| closed form for m = 3 | 2^(n + 3) - 3 |
| one row down: A(2, 4) | 11 |
| one step along: A(3, 5) | 253 |
A(4, 1)
(m = 4 · 1)
| Ackermann value A(4, 1) | 65,533 |
| closed form for m = 4 | 2 tetrated (n + 3), minus 3 |
| inner call A(4, 0) | 13 |
| digits in the value | 5 |
The three-line definition
A(0, n) = n + 1: the successor. A(m, 0) = A(m - 1, 1): a row starts from the previous row's second value. A(m, n) = A(m - 1, A(m, n - 1)): to move one step along a row, apply the previous row to the current value. Everything follows from these three clauses - including the monsters. The recursion always terminates (each call either lowers m or lowers n at fixed m), which is part of the point: the function is total and computable, just not primitive recursive.
The calculator's worked example A(2, 3) = 9 shows the machinery at human scale, and its supporting values trace the recursion's skeleton: one row down, A(1, 3) = 5; one step along, A(2, 4) = 11. The closed form for row 2, 2n + 3, predicts both: 2 x 3 + 3 = 9 and 2 x 4 + 3 = 11.
- A(0, n) = n + 1; A(m, 0) = A(m - 1, 1)
- A(m, n) = A(m - 1, A(m, n - 1))
- A(2, 3) = 9; A(1, 3) = 5; A(2, 4) = 11
Row by row: the closed forms
Row 0 adds one. Row 1 adds two: A(1, n) = n + 2. Row 2 is multiplication in disguise: A(2, n) = 2n + 3. Row 3 is exponentiation: A(3, n) = 2^(n + 3) - 3, so A(3, 4) = 2^7 - 3 = 125 and one step along, A(3, 5) = 2^8 - 3 = 253. Row 4 is tetration - iterated exponentiation: A(4, n) = (a tower of 2s of height n + 3) - 3, so A(4, 0) = 2^2^2 - 3 = 13 and A(4, 1) = 2^2^2^2 - 3 = 65,533.
The pattern is the hyperoperation ladder: each row iterates the previous row's operation, climbing from successor to addition to multiplication to exponentiation to tetration. Row 5 would iterate tetration, and its second value already defies notation. The calculator states the active row's closed form with every result, because for m >= 3 the formula is the only practical way to 'compute' anything.
- A(2, n) = 2n + 3; A(3, n) = 2^(n + 3) - 3
- A(3, 4) = 125; A(3, 5) = 253
- A(4, 0) = 13; A(4, 1) = 65,533
A(4, 2): where notation gives up
A(4, 2) is a power tower of five 2s, minus 3: equivalently 2^65,536 - 3. The exponent alone is 65,536, and the value has 19,729 digits. It is a perfectly definite integer - the recursion defines it, the closed form names it - but writing it out is a book-length exercise, and A(4, 3), a tower of six 2s, has a number of digits that itself has 19,729 digits. The calculator therefore reports A(4, 2) in its closed form rather than as a decimal string, and caps direct evaluation where honesty requires.
This is the function's pedagogical payload: primitive recursive functions - anything buildable from bounded loops - cannot grow this fast, and Ackermann's 1928 construction proved it by exhibiting a total computable function that eventually outruns every one of them. The inverse of this growth, by the way, is the absurdly slow function that appears in the analysis of union-find data structures: the two are the same cliff, viewed from opposite sides.
- A(4, 2) = 2^65,536 - 3, with 19,729 digits
- Ackermann, 1928: computable but not primitive recursive
- Its inverse governs union-find complexity
How the calculator evaluates
For small arguments the calculator runs the recursion directly (with the call structure the definition dictates), and for the standard rows it uses the closed forms, cross-checked against the recursion where both are feasible: A(3, 4) = 125 by formula and by recursion; A(4, 1) = 65,533 by the tower form. The reported extras - one row down, one step along, the digit count where meaningful (65,533 has 5 digits) - let the growth be felt comparatively rather than merely asserted.
The supported window is m from 0 to 4 with n bounded per row, because beyond it the honest output is a formula, not a number. When the closed form is the answer, the page says so plainly: '2 tetrated (n + 3), minus 3' is a complete and exact specification of A(4, n), more truthful than a truncated decimal would be.
The cross-checks deserve a moment, because they are the difference between a calculator and an assertion. Row 2's formula 2n + 3 and the raw recursion agree at A(2, 3) = 9 and A(2, 4) = 11; row 3's formula 2^(n + 3) - 3 and the recursion agree at A(3, 4) = 125; and the tower form reproduces A(4, 0) = 13 and A(4, 1) = 65,533, values the recursion also reaches - slowly, through a call tree with millions of nodes for the second. Where the two methods overlap, they match exactly; where they do not overlap, the formula is used and the recursion's agreement below is the evidence for trusting it.
- Recursion for small cases, closed forms beyond
- Cross-checked: A(3, 4) = 125 both ways
- Beyond the window, the formula is the answer
Why computer science keeps it
Beyond the recursion-theory milestone, the Ackermann function is a practical instrument. Its inverse - the slowest-growing function in common use - bounds the amortised cost of union-find with path compression, one of the most-used data structures in existence. Benchmark suites use Ackermann calls to stress recursion and stack handling, because the call counts explode along a precisely understood curve. And in computability courses it remains the first concrete proof that 'computable' is strictly larger than 'loop-definable'.
Wilhelm Ackermann published the function in 1928 (a three-argument ancestor of today's two-argument form, which follows Rózsa Péter and Raphael Robinson's simplification). Nearly a century later it is still the canonical answer to a student's reasonable question: can a simple definition really outgrow every loop? A(4, 2) = 2^65,536 - 3 is the three-line proof that it can.
- Inverse Ackermann: union-find's bound
- A recursion benchmark with a known curve
- Ackermann 1928; simplified by Péter and Robinson
Using the calculator
Enter m and n within the supported window. The result includes the value (or its exact closed form when the value is astronomical), the row's closed-form formula, the value one row down, and the value one step along the row. Compare A(3, 4) = 125 with A(4, 1) = 65,533 to feel what one row costs; then read A(4, 2)'s closed form and consider that the same three-line definition produced all of them.
Start at A(2, 3) = 9 and climb deliberately - row by row, step by step - because the function's whole lesson is in the climb: nothing in the definition changes, and everything about the size does.
- Value plus row formula plus neighbours
- Climb: A(2, 3) = 9, A(3, 4) = 125, A(4, 1) = 65,533
- A(4, 2) reported as 2^65,536 - 3
FAQs
What is the Ackermann function?
A(0, n) = n + 1; A(m, 0) = A(m - 1, 1); A(m, n) = A(m - 1, A(m, n - 1)). It is total and computable but not primitive recursive - Ackermann's 1928 proof that simple recursion outgrows every loop scheme.
What is A(3, 4)?
125. Row 3 has the closed form 2^(n + 3) - 3, so A(3, 4) = 2^7 - 3 = 125, and A(3, 5) = 253.
What is A(4, 1)?
65,533 - a power tower of four 2s (2^2^2^2 = 65,536) minus 3, a value with 5 digits. The inner call A(4, 0) = 13.
What is A(4, 2)?
2^65,536 - 3: a power tower of five 2s, minus 3 - in plain terms, 2 raised to the 65,536th power, minus 3, a number with 19,729 digits. The calculator reports it in this exact closed form.
What is A(2, 3)?
9. Row 2 has the closed form 2n + 3, so A(2, 3) = 9 and A(2, 4) = 11; one row down, A(1, 3) = 5.
Why is the Ackermann function famous?
It proved that not every computable function is primitive recursive, and its inverse bounds the cost of the union-find data structure. Its rows climb the hyperoperation ladder: addition, multiplication, exponentiation, tetration.