In
computability theory
Computability theory, also known as recursion theory, is a branch of mathematical logic, computer science, and the theory of computation that originated in the 1930s with the study of computable functions and Turing degrees. The field has since ex ...
, a primitive recursive function is, roughly speaking, a function that can be computed by a
computer program
A computer program is a sequence or set of instructions in a programming language for a computer to Execution (computing), execute. It is one component of software, which also includes software documentation, documentation and other intangibl ...
whose
loops are all
"for" loops (that is, an upper bound of the number of iterations of every loop is fixed before entering the loop). Primitive recursive functions form a strict
subset
In mathematics, a Set (mathematics), set ''A'' is a subset of a set ''B'' if all Element (mathematics), elements of ''A'' are also elements of ''B''; ''B'' is then a superset of ''A''. It is possible for ''A'' and ''B'' to be equal; if they a ...
of those
general recursive functions that are also
total functions.
The importance of primitive recursive functions lies in the fact that most
computable functions that are studied in
number theory
Number theory is a branch of pure mathematics devoted primarily to the study of the integers and arithmetic functions. Number theorists study prime numbers as well as the properties of mathematical objects constructed from integers (for example ...
(and more generally in mathematics) are primitive recursive. For example,
addition
Addition (usually signified by the Plus and minus signs#Plus sign, plus symbol, +) is one of the four basic Operation (mathematics), operations of arithmetic, the other three being subtraction, multiplication, and Division (mathematics), divis ...
and
division, the
factorial
In mathematics, the factorial of a non-negative denoted is the Product (mathematics), product of all positive integers less than or equal The factorial also equals the product of n with the next smaller factorial:
\begin
n! &= n \times ...
and
exponential function, and the function which returns the ''n''th prime are all primitive recursive. In fact, for showing that a computable function is primitive recursive, it suffices to show that its
time complexity is bounded above by a primitive recursive function of the input size. It is hence not particularly easy to devise a
computable function that is ''not'' primitive recursive; some examples are shown in section below.
The set of primitive recursive functions is known as
PR in
computational complexity theory
In theoretical computer science and mathematics, computational complexity theory focuses on classifying computational problems according to their resource usage, and explores the relationships between these classifications. A computational problem ...
.
Definition
A primitive recursive function takes a fixed number of arguments, each a
natural number
In mathematics, the natural numbers are the numbers 0, 1, 2, 3, and so on, possibly excluding 0. Some start counting with 0, defining the natural numbers as the non-negative integers , while others start with 1, defining them as the positive in ...
(nonnegative integer: ), and returns a natural number. If it takes ''n'' arguments it is called ''n''-
ary.
The basic primitive recursive functions are given by these
axiom
An axiom, postulate, or assumption is a statement that is taken to be true, to serve as a premise or starting point for further reasoning and arguments. The word comes from the Ancient Greek word (), meaning 'that which is thought worthy or ...
s:
More complex primitive recursive functions can be obtained by applying the
operations given by these axioms:
The primitive recursive functions are the basic functions and those obtained from the basic functions by applying these operations a finite number of times.
Examples
Addition
A definition of the 2-ary function
, to compute the sum of its arguments, can be obtained using the primitive recursion operator
. To this end, the well-known equations
:
are "rephrased in primitive recursive function terminology": In the definition of
, the first equation suggests to choose
to obtain
; the second equation suggests to choose
to obtain
. Therefore, the addition function can be defined as
. As a computation example,
:
Doubling
Given
, the 1-ary function
doubles its argument,
.
Multiplication
In a similar way as addition, multiplication can be defined by
. This reproduces the well-known multiplication equations:
:
and
:
Predecessor
The predecessor function acts as the "opposite" of the successor function and is recursively defined by the rules
and
. A primitive recursive definition is
. As a computation example,
:
Truncated subtraction
The limited subtraction function (also called "
monus", and denoted "
") is definable from the predecessor function. It satisfies the equations
:
Since the recursion runs over the second argument, we begin with a primitive recursive definition of the reversed subtraction,
. Its recursion then runs over the first argument, so its primitive recursive definition can be obtained, similar to addition, as
. To get rid of the reversed argument order, then define
. As a computation example,
:
Converting predicates to numeric functions
In some settings it is natural to consider primitive recursive functions that take as inputs tuples that mix numbers with
truth value
In logic and mathematics, a truth value, sometimes called a logical value, is a value indicating the relation of a proposition to truth, which in classical logic has only two possible values ('' true'' or '' false''). Truth values are used in ...
s (that is
for true and
for false), or that produce truth values as outputs. This can be accomplished by identifying the truth values with numbers in any fixed manner. For example, it is common to identify the truth value
with the number
and the truth value
with the number
. Once this identification has been made, the
characteristic function of a set
, which always returns
or
, can be viewed as a predicate that tells whether a number is in the set
. Such an identification of predicates with numeric functions will be assumed for the remainder of this article.
Predicate "Is zero"
As an example for a primitive recursive predicate, the 1-ary function
shall be defined such that
if
, and
, otherwise. This can be achieved by defining
. Then,
and e.g.
.
Predicate "Less or equal"
Using the property
, the 2-ary function
can be defined by
. Then
if
, and
, otherwise. As a computation example,
:
Predicate "Greater or equal"
Once a definition of
is obtained, the converse predicate can be defined as
. Then,
is true (more precisely: has value 1) if, and only if,
.
If-then-else
The 3-ary if-then-else operator known from programming languages can be defined by
. Then, for arbitrary
,
:
and
:
.
That is,
returns the then-part,
, if the if-part,
, is true, and the else-part,
, otherwise.
Junctors
Based on the
function, it is easy to define logical junctors. For example, defining
, one obtains
, that is,
is true
if, and only if, both
and
are true (
logical conjunction
In logic, mathematics and linguistics, ''and'' (\wedge) is the Truth function, truth-functional operator of conjunction or logical conjunction. The logical connective of this operator is typically represented as \wedge or \& or K (prefix) or ...
of
and
).
Similarly,
and
lead to appropriate definitions of
disjunction
In logic, disjunction (also known as logical disjunction, logical or, logical addition, or inclusive disjunction) is a logical connective typically notated as \lor and read aloud as "or". For instance, the English language sentence "it is ...
and
negation
In logic, negation, also called the logical not or logical complement, is an operation (mathematics), operation that takes a Proposition (mathematics), proposition P to another proposition "not P", written \neg P, \mathord P, P^\prime or \over ...
:
and
.
Equality predicate
Using the above functions
,
and
, the definition
implements the equality predicate. In fact,
is true if, and only if,
equals
.
Similarly, the definition
implements the predicate "less-than", and
implements "greater-than".
Other operations on natural numbers
Exponentiation
In mathematics, exponentiation, denoted , is an operation (mathematics), operation involving two numbers: the ''base'', , and the ''exponent'' or ''power'', . When is a positive integer, exponentiation corresponds to repeated multiplication ...
and
primality testing are primitive recursive. Given primitive recursive functions
,
,
, and
, a function that returns the value of
when
and the value of
otherwise is primitive recursive.
Operations on integers and rational numbers
By using
Gödel numberings, the primitive recursive functions can be extended to operate on other objects such as integers and
rational number
In mathematics, a rational number is a number that can be expressed as the quotient or fraction of two integers, a numerator and a non-zero denominator . For example, is a rational number, as is every integer (for example,
The set of all ...
s. If integers are encoded by Gödel numbers in a standard way, the arithmetic operations including addition, subtraction, and multiplication are all primitive recursive. Similarly, if the rationals are represented by Gödel numbers then the
field operations are all primitive recursive.
Some common primitive recursive functions
The following examples and definitions are from . Many appear with proofs. Most also appear with similar names, either as proofs or as examples, in they add the logarithm lo(x, y) or lg(x, y) depending on the exact derivation.
In the following the mark " ' ", e.g. a', is the primitive mark meaning "the successor of", usually thought of as " +1", e.g. a +1 =
def a'. The functions 16–20 and #G are of particular interest with respect to converting primitive recursive predicates to, and extracting them from, their "arithmetical" form expressed as
Gödel numbers.
:# Addition: a+b
:# Multiplication: a×b
:# Exponentiation: a
b
:# Factorial a! : 0! = 1, a'! = a!×a'
:# pred(a): (Predecessor or decrement): If a > 0 then a−1 else 0
:# Proper subtraction a ∸ b: If a ≥ b then a−b else 0
:# Minimum(a
1, ... a
n)
:# Maximum(a
1, ... a
n)
:# Absolute difference: , a−b , =
def (a ∸ b) + (b ∸ a)
:# ~sg(a): NOT
ignum(a) If a=0 then 1 else 0
:# sg(a): signum(a): If a=0 then 0 else 1
:# a , b: (a divides b): If b=k×a for some k then 0 else 1
:# Remainder(a, b): the leftover if b does not divide a "evenly". Also called MOD(a, b)
:# a = b: sg , a − b , (Kleene's convention was to represent ''true'' by 0 and ''false'' by 1; presently, especially in computers, the most common convention is the reverse, namely to represent ''true'' by 1 and ''false'' by 0, which amounts to changing sg into ~sg here and in the next item)
:# a < b: sg( a' ∸ b )
:# Pr(a): a is a prime number Pr(a) =
def a>1 & NOT(Exists c)
1 a :# pi: the i+1th prime number
:# (a)i: exponent of pi in a: the unique x such that pix, a & NOT(pix', a)
:# lh(a): the "length" or number of non-vanishing exponents in a
:# lo(a, b): (logarithm of a to base b): If a, b > 1 then the greatest x such that bx , a else 0
: ''In the following, the abbreviation x =def x1, ... xn; subscripts may be applied if the meaning requires.''
* #A: A function φ definable explicitly from functions Ψ and constants q1, ... qn is primitive recursive in Ψ.
* #B: The finite sum Σy ψ(x, y) and product Πyψ(x, y) are primitive recursive in ψ.
* #C: A ''predicate'' P obtained by substituting functions χ1,..., χm for the respective variables of a predicate Q is primitive recursive in χ1,..., χm, Q.
* #D: The following ''predicates'' are primitive recursive in Q and R:
::* NOT_Q(x) .
::* Q OR R: Q(x) V R(x),
::* Q AND R: Q(x) & R(x),
::* Q IMPLIES R: Q(x) → R(x)
::* Q is equivalent to R: Q(x) ≡ R(x)
* #E: The following ''predicates'' are primitive recursive in the ''predicate'' R:
::* (Ey)y R(x, y) where (Ey)y denotes "there exists at least one y that is less than z such that"
::* (y)y R(x, y) where (y)y denotes "for all y less than z it is true that"
::* μyy R(x, y). The operator μyy R(x, y) is a ''bounded'' form of the so-called minimization- or mu-operator: Defined as "the least value of y less than z such that R(x, y) is true; or z if there is no such value."
* #F: Definition by cases: The function defined thus, where Q1, ..., Qm are mutually exclusive ''predicates'' (or "ψ(x) shall have the value given by the first clause that applies), is primitive recursive in φ1, ..., Q1, ... Qm:
:: φ(x) =
::* φ1(x) if Q1(x) is true,
::* . . . . . . . . . . . . . . . . . . .
::* φm(x) if Qm(x) is true
::* φm+1(x) otherwise
* #G: If φ satisfies the equation:
:: φ(y,x) = χ(y, COURSE-φ(y; x2, ... xn ), x2, ... xn then φ is primitive recursive in χ. The value COURSE-φ(y; x2 to n ) of the course-of-values function encodes the sequence of values φ(0,x2 to n), ..., φ(y-1,x2 to n) of the original function.
Relationship to recursive functions
The broader class of partial recursive functions is defined by introducing an unbounded search operator. The use of this operator may result in a partial function
In mathematics, a partial function from a set to a set is a function from a subset of (possibly the whole itself) to . The subset , that is, the '' domain'' of viewed as a function, is called the domain of definition or natural domain ...
, that is, a relation with ''at most'' one value for each argument, but does not necessarily have ''any'' value for any argument (see domain). An equivalent definition states that a partial recursive function is one that can be computed by a Turing machine
A Turing machine is a mathematical model of computation describing an abstract machine that manipulates symbols on a strip of tape according to a table of rules. Despite the model's simplicity, it is capable of implementing any computer algori ...
. A total recursive function is a partial recursive function that is defined for every input.
Every primitive recursive function is total recursive, but not all total recursive functions are primitive recursive. The Ackermann function
In computability theory, the Ackermann function, named after Wilhelm Ackermann, is one of the simplest and earliest-discovered examples of a total function, total computable function that is not Primitive recursive function, primitive recursive. ...
''A''(''m'',''n'') is a well-known example of a total recursive function (in fact, provable total), that is not primitive recursive. There is a characterization of the primitive recursive functions as a subset of the total recursive functions using the Ackermann function. This characterization states that a function is primitive recursive if and only if
In logic and related fields such as mathematics and philosophy, "if and only if" (often shortened as "iff") is paraphrased by the biconditional, a logical connective between statements. The biconditional is true in two cases, where either bo ...
there is a natural number ''m'' such that the function can be computed by a Turing machine that always halts within A(''m'',''n'') or fewer steps, where ''n'' is the sum of the arguments of the primitive recursive function.
An important property of the primitive recursive functions is that they are a recursively enumerable subset of the set of all total recursive functions (which is not itself recursively enumerable). This means that there is a single computable function ''f''(''m'',''n'') that enumerates the primitive recursive functions, namely:
* For every primitive recursive function ''g'', there is an ''m'' such that ''g''(''n'') = ''f''(''m'',''n'') for all ''n'', and
* For every ''m'', the function ''h''(''n'') = ''f''(''m'',''n'') is primitive recursive.
''f'' can be explicitly constructed by iteratively repeating all possible ways of creating primitive recursive functions. Thus, it is provably total. One can use a diagonalization argument to show that ''f'' is not recursive primitive in itself: had it been such, so would be ''h''(''n'') = ''f''(''n'',''n'')+1. But if this equals some primitive recursive function, there is an ''m'' such that ''h''(''n'') = ''f''(''m'',''n'') for all ''n'', and then ''h''(''m'') = ''f''(''m'',''m''), leading to contradiction.
However, the set of primitive recursive functions is not the ''largest'' recursively enumerable subset of the set of all total recursive functions. For example, the set of provably total functions (in Peano arithmetic) is also recursively enumerable, as one can enumerate all the proofs of the theory. While all primitive recursive functions are provably total, the converse is not true.
Limitations
Primitive recursive functions tend to correspond very closely with our intuition of what a computable function must be. Certainly the initial functions are intuitively computable (in their very simplicity), and the two operations by which one can create new primitive recursive functions are also very straightforward. However, the set of primitive recursive functions does not include every possible total computable function—this can be seen with a variant of Cantor's diagonal argument
Cantor's diagonal argument (among various similar namesthe diagonalisation argument, the diagonal slash argument, the anti-diagonal argument, the diagonal method, and Cantor's diagonalization proof) is a mathematical proof that there are infin ...
. This argument provides a total computable function that is not primitive recursive. A sketch of the proof is as follows:
This argument can be applied to any class of computable (total) functions that can be enumerated in this way, as explained in the article Machine that always halts. Note however that the ''partial'' computable functions (those that need not be defined for all arguments) can be explicitly enumerated, for instance by enumerating Turing machine encodings.
Other examples of total recursive but not primitive recursive functions are known:
*The function that takes ''m'' to Ackermann(''m'',''m'') is a unary total recursive function that is not primitive recursive.
*The Paris–Harrington theorem involves a total recursive function that is not primitive recursive.
*The Sudan function
*The Goodstein function
Variants
Constant functions
Instead of ,
alternative definitions use just one 0-ary ''zero function'' as a primitive function that always returns zero, and built the constant functions from the zero function, the successor function and the composition operator.
Iterative functions
Robinson considered various restrictions of the recursion rule. One is the so-called ''iteration rule'' where the function ''h'' does not have access to the parameters ''xi'' (in this case, we may assume without loss of generality that the function ''g'' is just the identity, as the general case can be obtained by substitution):
:
He proved that the class of all primitive recursive functions can still be obtained in this way.
Pure recursion
Another restriction considered by Robinson is ''pure recursion'', where ''h'' does not have access to the induction variable ''y'':
:
Gladstone proved that this rule is enough to generate all primitive recursive functions. Gladstone improved this so that even the combination of these two restrictions, i.e., the ''pure iteration'' rule below, is enough:
:
Further improvements are possible: Severin prove that even the pure iteration rule ''without parameters'', namely
:
suffices to generate all unary primitive recursive functions if we extend the set of initial functions with truncated subtraction ''x ∸ y''. We get ''all'' primitive recursive functions if we additionally include + as an initial function.
Additional primitive recursive forms
Some additional forms of recursion also define functions that are in fact
primitive recursive. Definitions in these forms may be easier to find or
more natural for reading or writing. Course-of-values recursion defines primitive recursive functions. Some forms of mutual recursion also define primitive recursive functions.
The functions that can be programmed in the LOOP programming language are exactly the primitive recursive functions. This gives a different characterization of the power of these functions. The main limitation of the LOOP language, compared to a Turing-complete language, is that in the LOOP language the number of times that each loop will run is specified before the loop begins to run.
Computer language definition
An example of a primitive recursive programming language is one that contains basic arithmetic operators (e.g. + and −, or ADD and SUBTRACT), conditionals and comparison (IF-THEN, EQUALS, LESS-THAN), and bounded loops, such as the basic for loop
In computer science, a for-loop or for loop is a control flow Statement (computer science), statement for specifying iteration. Specifically, a for-loop functions by running a section of code repeatedly until a certain condition has been satisfi ...
, where there is a known or calculable upper bound to all loops (FOR i FROM 1 TO n, with neither i nor n modifiable by the loop body). No control structures of greater generality, such as while loops or IF-THEN plus GOTO, are admitted in a primitive recursive language.
The LOOP language, introduced in a 1967 paper by Albert R. Meyer and Dennis M. Ritchie, is such a language. Its computing power coincides with the primitive recursive functions. A variant of the LOOP language is Douglas Hofstadter
Douglas Richard Hofstadter (born 15 February 1945) is an American cognitive and computer scientist whose research includes concepts such as the sense of self in relation to the external world, consciousness, analogy-making, Strange loop, strange ...
's BlooP in ''Gödel, Escher, Bach
''Gödel, Escher, Bach: an Eternal Golden Braid'' (abbreviated as ''GEB'') is a 1979 nonfiction book by American cognitive scientist Douglas Hofstadter.
By exploring common themes in the lives and works of logician Kurt Gödel, artist M. C. Esc ...
''. Adding unbounded loops (WHILE, GOTO) makes the language general recursive and Turing-complete, as are all real-world computer programming languages.
The definition of primitive recursive functions implies that their computation halts on every input (after a finite number of steps). On the other hand, the halting problem
In computability theory (computer science), computability theory, the halting problem is the problem of determining, from a description of an arbitrary computer program and an input, whether the program will finish running, or continue to run for ...
is undecidable for general recursive functions.
Finitism and consistency results
The primitive recursive functions are closely related to mathematical finitism, and are used in several contexts in mathematical logic where a particularly constructive system is desired. Primitive recursive arithmetic (PRA), a formal axiom system for the natural numbers and the primitive recursive functions on them, is often used for this purpose.
PRA is much weaker than Peano arithmetic, which is not a finitistic system. Nevertheless, many results in number theory
Number theory is a branch of pure mathematics devoted primarily to the study of the integers and arithmetic functions. Number theorists study prime numbers as well as the properties of mathematical objects constructed from integers (for example ...
and in proof theory
Proof theory is a major branchAccording to , proof theory is one of four domains mathematical logic, together with model theory, axiomatic set theory, and recursion theory. consists of four corresponding parts, with part D being about "Proof The ...
can be proved in PRA. For example, Gödel's incompleteness theorem can be formalized into PRA, giving the following theorem:
:If ''T'' is a theory of arithmetic satisfying certain hypotheses, with Gödel sentence ''G''''T'', then PRA proves the implication Con(''T'')→''G''''T''.
Similarly, many of the syntactic results in proof theory can be proved in PRA, which implies that there are primitive recursive functions that carry out the corresponding syntactic transformations of proofs.
In proof theory and set theory
Set theory is the branch of mathematical logic that studies Set (mathematics), sets, which can be informally described as collections of objects. Although objects of any kind can be collected into a set, set theory – as a branch of mathema ...
, there is an interest in finitistic consistency proof
In deductive logic, a consistent theory (mathematical logic), theory is one that does not lead to a logical contradiction. A theory T is consistent if there is no Formula (mathematical logic), formula \varphi such that both \varphi and its negat ...
s, that is, consistency proofs that themselves are finitistically acceptable. Such a proof establishes that the consistency of a theory ''T'' implies the consistency of a theory ''S'' by producing a primitive recursive function that can transform any proof of an inconsistency from ''S'' into a proof of an inconsistency from ''T''. One sufficient condition for a consistency proof to be finitistic is the ability to formalize it in PRA. For example, many consistency results in set theory that are obtained by forcing can be recast as syntactic proofs that can be formalized in PRA.
History
Recursive definitions had been used more or less formally in mathematics before, but the construction of primitive recursion is traced back to Richard Dedekind's theorem 126 of his ''Was sind und was sollen die Zahlen?'' (1888). This work was the first to give a proof that a certain recursive construction defines a unique function.
Primitive recursive arithmetic was first proposed by Thoralf Skolem[ Thoralf Skolem (1923) "The foundations of elementary arithmetic" in Jean van Heijenoort, translator and ed. (1967) ''From Frege to Gödel: A Source Book in Mathematical Logic, 1879-1931''. Harvard Univ. Press: 302-33.] in 1923.
The current terminology was coined by Rózsa Péter (1934) after Ackermann had proved in 1928 that the function which today is named after him was not primitive recursive, an event which prompted the need to rename what until then were simply called recursive functions.
See also
* Grzegorczyk hierarchy
* Recursion (computer science)
In computer science, recursion is a method of solving a computational problem where the solution depends on solutions to smaller instances of the same problem. Recursion solves such recursion, recursive problems by using function (computer sc ...
* Primitive recursive functional
* Double recursion
* Primitive recursive set function
* Primitive recursive ordinal function
* Tail call
Notes
References
*
*
* Robert I. Soare, ''Recursively Enumerable Sets and Degrees'', Springer-Verlag, 1987.
* Chapter XI. General Recursive Functions §57
*
*
*
*
*
*
{{Mathematical logic
Computability theory
Theory of computation
Functions and mappings
Recursion