Definition
Primitive Recursion
Primitive recursion is a function schema that defines from a base function and a step function .
The recursion is over the first argument.
Base Functions
Constant Function
Definition
Link to originalConstant Function (Recursion)
Examples:
Successor Function
Definition
Link to originalSuccessor Function (Recursion)
Examples:
Projection Function
Definition
Link to originalProjection Function (Recursion)
Examples:
Arithmetic Functions
Addition
We can define addition recursively as:
We observe that the definition recurses over the first argument of . Thus, we can define addition via the recursion operator as:
, , ,
Multiplication
We can define multiplication recursively as:
We observe that the definition recurses over the first argument of . Thus, we can define multiplication via the recursion operator as:
Intuition
Here, we have a function with two parameters:
- the parameter to be recursed over
- the parameter to be repeatedly added times.
If , then . We select as arity given that only has one non-recursion parameter (the second one; ).
If , we have to add the quantity to the previous iteration , where:
- is the previous result, i.e. , and
- is the parameter (the only non-recursive one)
Together, we add:
Factorial
We can define factorial recursively as:
We observe that the definition recurses over the first argument of . Thus, we can define multiplication via the recursion operator as:
Signum
Truncated Predecessor Function
The truncate predecessor function, i.e. the predecessor function for , can be defined as:
Truncated Subtraction
Let be the truncated subtraction defined as:
Then, we can define it using the primitive recursion operator as follows:
Negation
We can define as:
Conjunction
We can define as:
Disjunction
Less Than
Computability
Primitive-recursive functions are computable and total. However, not every computable total function is primitive-recursive.
We can list all primitive-recursive functions as . This gives the following table:
Then the diagonal function
is computable and total.
For any fixed , compare with at input :
The output of is exactly one larger than the output of at that input. Therefore, . Since equal functions must agree on every input, . This holds for every , so is not primitive-recursive.
Not all total computable functions are primitive-recursive
Not all computable total functions are primitive-recursive.
Ackermann function
The Ackermann function is computable and total, but not primitive-recursive.
Guaranteed termination forces incompleteness
There is no programming language in which every program terminates and in which every total computable function is expressible.
Examples
Examples: Using Base Functions
Example
Example
Example
Example
Example
Example
We want to find an equivalent -expression for:
First, we want to represent recursively:
Now, it’s easier to write as -expresion:
The above immediately increments , as the never uses alone and uses multiple times in the recursive definition.