Primitive recursion and arithmetic encoding
Build total finite computations and encode sequences with a fully declared prime-exponent convention.
On this page
The question for today
What you’ll understand
- Define primitive recursion and explain its guaranteed termination.
- Encode and decode finite sequences using nonzero consecutive-prime exponents.
- Separate finite proof checking from the unbounded search for a proof.
To discuss formulas and proofs inside arithmetic, finite symbolic objects must first become natural numbers with effective operations. A code is a convention, not a mysterious numerical meaning attached to a sentence. We will choose one explicit sequence encoding, calculate it in both directions, and explain why checking a finite certificate can be a total computation even when searching for any successful certificate is not.
Primitive recursion controls how many predecessor steps are used
Start with zero, successor, and coordinate projections, then close under composition and primitive recursion. A recursion specifies the value at zero and obtains the next value from the current index, the previous value, and fixed parameters. On any natural input, only finitely many predecessor stages are required. Structural induction on definitions therefore proves every primitive recursive function total. Bounded searches and bounded quantifiers over primitive recursive predicates can also be implemented within this class.
For example, set T(0)=0 and add n+1 to pass from T(n) to T(n+1). This computes triangular sums without an unbounded stopping test. General computability is broader: unbounded minimization may produce partial functions, and there are total computable functions outside primitive recursion. One must not infer that every terminating program has a primitive recursive running-time bound or that its totality is automatically provable in a particular arithmetic theory.
Declare zero entries, length, and malformed-code behavior
For a finite sequence of natural numbers, use successive primes starting with two and raise prime i to the corresponding entry plus one. Encode the empty sequence as one. The plus one ensures that a zero entry still leaves a prime factor, so trailing zeros are not lost. Valid nonempty codes use precisely an initial consecutive segment of primes, each with positive exponent, and no other prime factors. A number with a gap, such as ten, is malformed under this convention.
Unique prime factorization recovers every exponent and hence every entry. For a positive candidate N, trial division and all required exponent searches can be bounded by N; standard bounded constructions make validity, length, and entry extraction primitive recursive, with declared default outputs for malformed codes or out-of-range indices. Efficient decoding is a separate issue: prime-exponent codes can grow very large. Other encodings may be more economical without changing the underlying computability results.
A finite certificate can be checked without solving its existence problem
Assign effective token numbers to symbols, then encode token sequences, parse trees, proof lines, and finite machine configurations. With standard carefully chosen encodings, syntactic parsing, substitution, and checking a bounded computation trace are primitive recursive. This is a constructive claim about finite local tests, not a claim that every arbitrary numbering has the same convenient complexity. Our elementary sequence code illustrates the first layer; a complete proof coding additionally specifies its grammar and inference rules.
For a theory with a merely c.e. axiom set, do not assume that an unsupported line's axiom status is decidable. Include a finite enumeration-stage certificate demonstrating that the line was emitted as an axiom, together with the ordinary inference checks. Bounded simulation verifies that certificate. The resulting certified proof relation can be primitive recursive in a standard encoding, while existence of some certified proof is expressed by an unbounded existential quantifier. The existential search is exactly where a decidability guarantee can fail.
Work it through
Decode a trace without losing its middle zero
Under the consecutive-prime exponent convention, encode the sequence (1,0,2), decode its numerical code, and check why omitting the plus one would corrupt a trailing zero. Treat the sequence as data rather than as a complete arithmetic proof.
Use primes 2,3,5 and exponents two, one, three. The product is . The middle zero still contributes a factor of three.
Factoring 1500 gives valuations two at prime two, one at prime three, and three at prime five. No further prime divides it. Subtract one from each positive exponent to recover exactly (1,0,2), with length three.
Without shifted exponents, the sequence (1,0) would give the same product as (1), namely two, because the final exponent zero contributes nothing. With our convention their codes are twelve and four respectively, so the last zero and the length remain recoverable.
The declared code of (1,0,2) is 1500. Its uniqueness follows from prime factorization together with the explicit length and zero-entry conventions.
The living notebook
Explore the model
Interactive lab · modular
Encode a finite arithmetic trace by hand
Pause and Reset, set modulus 5 and step 2, and take two Steps to see the prefix 0,2,4. Its sequence code is 2¹·3³·5⁵=168750 under the lesson convention. For a fresh comparison Reset and set both modulus 5 and step 1; after two Steps the prefix 0,1,2 has code 2¹·3²·5³=2250. The instrument displays residue transitions, not prime factorization or formal proof validation. Each Step is one addition, and editing without Reset would retain the clock.
- Residue r0
- 0
- Orbit period · m/gcd(m,a)
- 12
- Distinct residues visited
- 1 of 12
Addition modulo m starts at zero: rₙ = na mod m. Playback advances two additions per second. The orbit has period m/gcd(m,a), including period one for a = 0. This is not a cryptographic security test or a primality algorithm. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forFinite transition data can be encoded effectively, but validity of a larger proof requires additional specified tests.
Pause & reason
Check your understanding
Your turn
Try it yourself
Encode and decode (0,2,1). Explain why ten is malformed under this convention. Then compute T(4) and T(5) from the triangular recursion, keeping this numerical calculation separate from the sequence code.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
The sequence uses the first three primes and exponents one, three, two. A valid nonempty sequence code may not skip the prime three.
Compare with the solution
The code is . Its prime valuations are one, three, two, which decode to (0,2,1). Ten has factors two and five but lacks three, so it cannot describe an initial consecutive prime segment and is rejected. The triangular recursion yields T(4)=10 and T(5)=15 by adding four and then five to the previous values. These values are ordinary function outputs, not alternate meanings of the sequence codes.
Keep the idea
Take it with you
- Primitive recursion gives total functions through explicitly finite recursive depth.
- A coding convention must preserve zero entries, sequence length, and syntactic validity.
- Decidable certificate checking does not make unbounded certificate existence decidable.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.