Primitive recursion — bounded loops, always halt
Parent: recursive-functions
The primitive recursive functionsThe smallest class containing the basic functions —
- zero
Z() = 0, successorS(n) = n+1, projectionsPᵢ(x₁,…,xₖ) = xᵢ— and closed under:- composition (plug functions into functions);
- primitive recursion: define
fbyf(0, x) = g(x)andf(n+1, x) = h(n, f(n, x), x), i.e. recurse on a counternthat strictly decreases to a base case.
Everything primitive recursive is totalEvery primitive recursive function halts on all inputs — the recursion is driven by a counter that counts down to
0, so it can't run forever. Primitive recursion = boundedfor-loops.
What it covers, and its ceiling
Addition, multiplication, exponentiation, factorial, bounded search, primality, gcd, coding/decoding of tuples — essentially every "everyday" total function is primitive recursive.
But the recursion depth is always bounded by the input: no for-loop nesting can encode a search whose length isn't known in advance. So the class is not all of the computable functions — the witness is Ackermann's function, which is total and computable but grows faster than any primitive recursive function. To go further you need unbounded search → general-recursion.