Computability is the part of logic and theoretical computer science that gives a mathematically precise formulation to the concepts algorithm, mechanical procedure, and calculable function (or relation). Its advent was strongly motivated, in the 1930s, by Hilbert’s program to found mathematics on a (metamathematically provably) consistent (cf. 1.1.1.51 ) axiomatic basis, in particular by his belief that the Entscheidungsproblem, or decision problem, for axiomatic theories, that is, the problem “is this formula a theorem of that theory?” was solvable by a mechanical procedure that was yet to be discovered.
Now, since antiquity, mathematicians have invented “mechanical procedures”, e.g., Euclid’s algorithm for the “greatest common divisor”, 49 and had no problem recognizing such procedures when they encountered them. But how do you mathematically prove the nonexistence of such a mechanical procedure for a particular problem? You need a mathematical formulation of what is a “mechanical procedure” in order to do that!
Intensive activity by many [Post (1936, 1944), Kleene (1936), Church (1936b), Turing (1936, 1937), and, later, Markov (1960)] led in the 1930s to several alternative formulations, each purporting to mathematically characterize the concepts algorithm, mechanical procedure, and calculable function. All these formulations were soon proved to be equivalent; that is, the calculable functions admitted by any one of them were the same as those that were admitted by any other. This led Alonzo Church to formulate his conjecture, famously known as “Church’s Thesis”, that any intuitively calculable function is also calculable within any of these mathematical frameworks of calculability or computability. 50
By the way, Church proved [Church (1936a,b)] that Hilbert’s fundamental Entscheidungsproblem admits no solution by functions that are calculable within any of the known mathematical frameworks of computability. Thus, if we accept his “thesis”, the Entscheidungsproblem admits no algorithmic solution, period!
The eventual introduction of computers further fueled the study of and research on the various mathematical frameworks of computation, “models of computation” as we often say, and “computability” is nowadays a vibrant and very extensive field. The model of computation that I will present here, due to Shepherdson and Sturgis (1963), is a later model that has been informed by developments in computer science, in particular, by the advent of so-called high level 51 programming languages.
2.1.1 A Programming Framework for Computable Functions
So, what is a computable function, mathematically speaking? There are two main ways to approach this question. One is to define a programming formalism—that is, a programming language—and say: “a function is computable precisely if it can be ‘programmed’ in the programming language”. Such programming languages are the Turing Machines (or TMs) of Turing and the unbounded register machines (or URMs) of Shepherdson and Sturgis. Note that the term machine in each case is a misnomer, as both the TM and the URM formulations are really programming languages, the first being very much like assembly language of “real” computers, the latter reminding us more of (subsets of) Algol (or Pascal).
The other main way is to define a set of computable functions inductively, as a C1(
,
)—cf. Section 1.6. To do so we start with some set of initial functions
that are immediately recognizable as “intuitively computable”, and choose a set
of function-building operations that preserve the “computable” property. This approach was originally due to Dedekind (1888) for what we nowadays call primitive recursive functions. It evolved later [Kleene (1936)] into what we nowadays call partial recursive functions. The definition of computable functions as members of some Cl(
,
) is very elegant mathematically [cf. Tourlakis (1984)], but is less intuitively immediate, whereas the programming approach has the attraction of appearing “natural” to those who have done some programming.
We now embark on defining the high level programming language URM. The alphabet of the language is
Just like any other high level programming language, URM manipulates the contents of variables. However, these are restricted to be of natural number type —i.e., the only data type that such variables can denote (or “hold”, or “contain”, in programming jargon) are members of
. Since this programming language is for theoretical considerations only—rather than practical implementation—every variable is allowed to hold any natural number whatsoever, without limitations to its size, hence the “UR” in the language name (“unbounded register”, used synonymously with variable of unbounded capacity ).
The syntax of the variables is simple: A variable (name) is a string that starts with X and continues with one or more 1:
Nevertheless, as is customary for the sake of convenience, we will utilize the bold face lower case letters x, y, z, u, v, w, with or without subscripts or primes as metavariables in most of our discussions of the URM, and in examples of specific programs (where yet more, convenient metanotations for variables may be employed).
A URM program is a finite (ordered) sequence of instructions (or commands) of the following five types:
where L, M, R, a, written in decimal notation, are in
, and x is some variable. We call instructions of the last type if-statements.
Each instruction in a URM program must be numbered by its position number, L, in the program, where “:” separates the position number from the instruction. We call these numbers labels. Thus, the label of the first instruction is always “1”. The instruction stop must occur only once in a program, as the last instruction.
The semantics of each command is given in the context of a URM computation. The latter we will let have its intuitive meaning in this subsection, and we will defer a mathematical definition until Section 2.3 , where such a definition will be needed.
Thus, for now, a computation is the process that cycles along the instructions of a program, during which process each instruction that is visited upon—the current instruction —causes an action that we usually term “the result of the execution” of the instruction. I said “cycles along” because instructions of the last two types (may) cause the computation to loop back or cycle, revisiting an instruction that was already visited by the computation.
Every computation begins with the instruction labeled “1” as the current instruction. The semantic action of instructions of each type is defined if and only if they are current, and is as follows:
(i) L : x ← a . Action: The value of x becomes the (natural) number a . Instruction L + 1 will be the next current instruction.
(ii) L : x ← x + 1. Action: This causes the value of x to increase by 1. The instruction labeled L + 1 will be the next current instruction.
(iii) L : x ← x
1. Action: This causes the value of x to decrease by 1, if it was originally non zero. Otherwise it remains 0. The instruction labeled L + 1 will be the next current instruction.
(iv) L : stop. Action: No variable (referenced in the program) changes value. The next current instruction is still the one labeled L.
(v) L : if x = 0 goto M else goto R. Action: No variable (referenced in the program) changes value. The next current instruction is numbered M if x = 0; otherwise it is numbered R.
This command is syntactically illegal (meaningless) if any of M or R exceed the label of the program’s stop instruction.
We say that a computation terminates, or halts, iff it ever makes current (as we say “reaches”) the instruction stop . Note that the semantics of “ L : stop ” appear to require the computation to continue ad infinitum, but it does so in a trivial manner where no variable changes value, and the current instruction remains the same: Practically, the computation is over.
One usually gives names to URM programs, or as we just say, “to URMs”, such as M, N, P, Q, R, F, H, G.
2.1.1.1 Definition. (Computing a Function) We say that a URM, M, computes a function f :
n →
of n arguments provided —for some choice of variables x 1 , ..., x n , of M that we designate as input variables and a choice of one variable y that we designate as the output variable —the following precise conditions hold for every choice of input sequence (or n -tuple), a 1 , ..., a n from
:
(1) We initialize the computation, by doing two things:
(a) We initialize the input variables with the input values a 1 , ..., a n . We initialize all other variables of M to be 0.
(b) We next make the instruction labeled “1” current, and thus start the computation.
(2) The computation terminates iff f ( a 1 , ..., a n ) is defined, or, symbolically, iff f ( a 1 , ..., a n ) ↓ (cf. p. 43 ).
(3) If the computation terminates, that is, if at some point the instruction stop becomes current, then the value of y at that point (and hence at any future point, by (iv) above), is f ( a 1 , ..., a n ).
(1) We recall that the notation “ f ( a 1 , ..., a n ) ↑” means that f ( a 1 , ..., a n ) is undefined (cf. p. 43 ).
(2) The function computed by a URM, M, with inputs and output designated as above, can also be denoted by the symbol
. This symbol, with no need for comment, makes it clear as to which are the input variables (superscript) of M , and which is the output variable (subscript). The variables x 1 , ..., x n in
are “apparent”, or not free for substitution, since
is not a term (in the logic sense of the word; cf. p. 3 ); it does not denote an object value. Note also that any attempt to effect such substitutions, for example,
, would lead, in general, to nonsensical situations like “ L : 3 ← 3 + 1”, a command that wants to change the (standard) value of the symbol “3” (from 3 to 4)!
Thus, we may write f =
, but not f ( a 1 , ..., a n ) =
.
Note that f denotes, by name, a function, that is, a potentially infinite table of input/output pairs, where the input is always an n -tuple. On the other hand,
goes a step further: It finitely represents the table f, being able to do so because it is a finite set of instructions that can be used to compute the output for each input where f is defined.
2.1.1.2 Definition. (Computable Functions) A function f :
n →
of n variables x 1 , ..., x n is called partial computable iff for some URM, M, we have f =
. The set of all partial computable functions is denoted by
. The set of all the total functions in
—that is, those that are defined on all inputs from
—is the set of computable functions and is denoted by
. The term recursive is used in the literature synonymously with the term computable.
2.1.1.3 Remark. Note that since a URM is a theoretical, rather than practical, model of computation we do not include human-computer interface considerations in the computation. Thus, the “input” and “output” phases just happen during initialization—they are not part of the computation. That is why we have dispensed with both read and write instructions and speak instead of initialization in (1) of 2.1.1.1. This approach to input/output is entirely analogous with the input/output convention for the other well-known model of computation, the Turing machine [cf. Davis (1958); Hoperoft et al. (2007); Lewis and Papadimitriou (1998); Sipser (1997); Tourlakis (1984)].
2.1.1.4 Example. Let M be the program
1 : x ← x + 1
2 : stop
Then
is the function f given, for all x
, by f ( x ) = x + 1, the successor function.
2.1.1.5 Remark. ( λ Notation) To avoid saying verbose things such as “
is the function f given, for all x
, by f ( x ) = x + 1”, we will often use Church’s λ-notation and write instead “
= λ x . x + 1”.
In general, the notation “λ · · · .” marks the beginning of a sequence of input variables “ · · · ” by the symbol “λ”, and the end of the sequence by the symbol “.” What comes after the period “.” is the “rule” that indicates how the output relates to the input. The template for λ-notation thus is
λ“input”.“output-rule”
Relating to the above example, we note that f = λ x . x + 1 = λ y . y + 1 = λ z . f ( z ) is correct—although the rule “ y + 1” is more informative than “ f ( z )”. To the left and right of each “=” we have (a symbol for) the table of a function, and we are saying that all these tables are the same. Note that x, y , z are “apparent” variables (“dummy” or bound) and are not free (for substitution). In particular, f = f ( x ) is incorrect as we have distinct data types to the left and right of “=”, namely, a table on one hand and a number on the other (albeit an unspecified number).
Pause. Why bother with these notational acrobatics?
Because well-chosen notation protects against meaningless statements, such as
that one might make in the context of the above example. As remarked before, “
” is not a term, nor are the occurrences of x in it free (for substitution). For example, “
= 4” [obtained by substituting 3 for x throughout in (1)] is totally meaningless, as it says
However,
= λ x . x + 1 does make syntactic and semantic sense; indeed it is true, as two tables are compared and are found to be equal! Since λ x . x + 1 = λ y . y + 1, the following three tables are identical: 52
In programming circles, the distinction between function definition or declaration, λ
. f (
), and function invocation (or call, or application, or “use”)—what we call a term, f (
), in logic parlance—is well established. The definition part, in programming, uses various notations depending on the programming language and corresponds to writing a program that implements the function, just as we did with M here.
However, there is a double standard in notation when it comes to relations. Extensionally, a relation R is a table (i.e., set) of n -tuples. Its counterpart in formal logic is a formula (cf. the discussion following Definition 1.2.0.4 ). But where in formal logic we rather infrequently write a formula A as A [ x ]—doing so only if we want to draw attention to our interest in its (free) variable x —in the metatheory we most frequently write a relation R as R (
n ), without employing λ notation, to draw attention to its “input slots”, which here are x 1 , ..., x n (i.e., its “free variables”).
Since stating “ R (
n )”, by convention, is short for stating “
n
”
R ”, we have two notations for a relation: Logical or relational, i.e., R (
n ), and set-theoretic, i.e.,
n
R, both without the benefit of λ notation. There are exceptions to this practice, for example, when we define one relation from another one via the process of “freezing” some of the original relation’s inputs. For example, writing x < y (the standard “less than” on
) means that both x and y are meant to be inputs; we have a table of ordered pairs. However, we will write λ x . x < y to convey that y is fixed and that the input is just x. Clearly, a different relation arises for each y ; we have an infinite family of tables: For y = 0 we have the empty table; for y = 1 one that contains just 0; for y = 2 one that contains just 0, 1; etc.
We wrote on p. 41
Thus, the relation (table) establishes a one-to-many input/output correspondence. Contrary to our viewpoint with formulae
( x , y )—where the input variables are all the free variables, here x and y —in the case of relations we are allowed two points of view; one being the one presented above, and the other where both x and y are the inputs of the relation R ( x , y ). The context will fend for us!
Our attitude in computability—the “context”—will be to view n-ary relations not as one-to-many correspondences
with n − 1 input-variables and one output variable, but rather as formulae R (
n ) of n free variables. This is already implicit in Remark 2.1.1.5 above, where we said “writing x < y (the standard “less than” on
) means that both x and y are meant to be inputs” and “we will write λ x . x < y to convey that y is fixed and that the input is just x ”.
2.1.1.6 Example. Let M be the program
1 : x ← x
1
2 : stop
Then
is the function λ x . x
1, the predecessor function. The operation
is called “proper subtraction” and is in general defined by
It ensures that subtraction (as modified) does not take us out of the set of the so-called number-theoretic functions, which are those with inputs from
and outputs in
.
Pause. Why are we restricting computability theory to number-theoretic functions? Surely, in practice we can compute with negative numbers, rational numbers, and with nonnumerical entities, such as graphs, trees, etc. Theory ought to reflect, and explain, our practices, no?
It does. Negative numbers and rational numbers can be coded by natural number pairs. Computability of number-theoretic functions can handle such pairing (and unpairing or decoding). Moreover, finite objects such as graphs, trees, and the like that we manipulate via computers can be also coded (and decoded) by natural numbers. After all, the internal representation of all data in computers is, at the lowest level, via natural numbers represented in binary notation. Computers cannot handle infinite objects such as (irrational) real numbers. But there is an extensive “higher type” computability theory [which originated with the work of Kleene (1943)] that can handle such numbers as inputs and also compute with them. However, this theory is beyond our scope.
2.1.1.7 Example. Let M be the program
1 : x ← 0
2 : stop
Then
is the function λ x .0, the zero function .
In Definition 2.1.1.2 we spoke of partial computable and total computable functions. We retain the qualifiers partial and total for all number-theoretic functions, even for those that may not be computable. Indeed, total vs. nontotal (no hyphen) has been defined with respect to some assumed left field for any relation, single-valued or not (cf. p. 42 ).
The set union of all total and nontotal number-theoretic functions is the set of all partial (number-theoretic) functions. Thus partial is not synonymous with nontotal.
2.1.1.8 Example. The unconditional goto instruction, namely, “ L : goto L ′”, can be simulated by L : if x = 0 goto L ′ else goto L ′.
2.1.1.9 Example. Let M be the program segment
k – 1 : x ← 0
k : x ← x + 1
k + 1 : z ← z
1
k + 2 : if z = 0 goto k + 3 else goto k
k + 3 : . . .
What it does, by the time the computation reaches instruction k + 3, is to have set the value of z to 0, and to make the value of x equal to the value that z had when instruction k – 1 was current. In short, the above sequence of instructions simulates the following sequence
L : x ← z
L + 1 : z ← 0
L + 2 : . . .
where the semantics of L : x ← z are standard in programming: They require that upon execution of the instruction the value of z is copied into x , but the value of z remains unchanged.
2.1.1.10 Exercise. Write a program segment that simulates precisely L : x ← z ; that is, copy the value of z into x without causing z to change as a side-effect.
Because of the above, without loss of generality, one may assume that any input variable, x , of a program M is read-only. This means that its value remains invariant throughout any computation of the program. Indeed, if x is not so, a new input variable, x ′, can be introduced as follows to relieve x from its input role: Add at the very beginning of M the (derived) instruction 1 : x ← x ′ of Exercise 2.1.1.10 , where x ′ is a variable that does not occur in M. Adjust all the following labels consistently, including, of course, the ones referenced by if-statements—a tedious but straightforward task. Call M ′ the so-obtained URM. Clearly,
=
, and M ′ does not change x ′.
2.1.1.11 Example. (Composing Computable Functions) Suppose that λ x
. f ( x ,
) and λ
. g (
) are partial computable, and say f =
while g =
.
Since we can rewrite any program, renaming its variables at will, we assume without loss of generality that x is the only variable common to F and G. Thus, if we concatenate the programs G and F in that order, and (1) remove the last instruction of G ( k : stop, for some k )—call the program segment that results from this G ′, and (2) renumber the instructions of F as k , k + 1, . . . (and, as a result, the references that if-statements of F make) in order to give ( G ′ F ) the correct program structure, then,
. Note that all non-input variables of F will still hold 0 as soon as the execution of ( G ′ F ) makes the first instruction of F current for the first time. This is because none of these can be changed by G ′ under our assumption, thus ensuring that F works as designed.
Thus, we have, by repeating the above a finite number of times:
2.1.1.12 Proposition. If λ
n . f (
n ) and λ
. g i (
), for i = 1, ..., n, are partial computable, then so is
.
We can rephrase 2.1.1.12 , saying simply that
is closed under composition. For the record, we will define composition to mean the somewhat rigidly defined operation used in 2.1.1.12 , that is:
2.1.1.13 Definition. Given any partial functions (computable or not) λ
n . f (
n ) and λ
. g i (
), for i = 1, ..., n, we say that
is the result of their composition.
We characterized the definition as “rigid”. Indeed, note that it requires all the arguments of f to be substituted by some g i (
)—unlike Example 2.1.1.11 , where we substituted a function invocation (cf. terminology in 2.1.1.5 ) only in one variable of f there, and did nothing with the variables
—and for each application g i (. . .) the argument list, “. . .”, must be the same, for example
. That is, in computability we only say, technically, that “we do composition” if—in the sense of 1.2.0.18 —we take an f :
n →
and the n -tuple-valued function
g 1 , ..., g n
:
m →
n 53 and form
g 1 , ..., g n
f .
As we will show in examples in the next subsection ( 2.1.2 ), this rigidity is only apparent.
Composing a number of times that depends on the value of an input variable —or as we may say, a variable number of times—is iteration. The general case of iteration is called primitive recursion.
2.1.1.14 Definition. (Primitive Recursion) A number-theoretic function f is defined by primitive recursion from given functions
and
provided, for all x ,
, its values are given by the two equations below:
h is the basis function, while g is the iterator. In 1.7.0.27 we saw that a unique f that satisfies the above schema exists. Moreover, if both h and g are total, then so is f and the ≃ in the schema may be replaced by = (cf. the exercise following 1.7.0.27 ).
It will be useful to use the notation f = prim ( h, g ) to indicate in shorthand that f is defined as above from h and g (note the order).
Note that
, etc. Thus the “ x -value”, 0, 1, 2, 3, etc., equals the number of times we compose g with itself (i.e., the number of times we iterate g ).
2.1.1.15 Example. (Iterating Computable Functions) Suppose that
and λ
. h (
) are partial computable, and, say,
while
.
By earlier remarks we may assume:
(i) The only variables that H and G have in common are z ,
.
(ii) The variables
are read-only in both H and G.
(iii) i is read-only in G.
(iv) x does not occur in any of H or G.
We can now argue that the following program, let us call it F, computes f defined as in 2.1.1.14 from h and g, where
is program H with the stop instruction removed,
is program G that has the stop instruction removed, and instructions renumbered (and if-statements adjusted) as needed:
r : i ← 0
r + 1 : if x = 0 goto k + m + 2 else goto r + 2
r + 2 : x ← x
1
k : i ← i + 1
k + 1 : w 1 ← 0
k + m : w m ← 0
k + m + 1 : goto r + 1
k + m + 2 : stop
The instructions w i ← 0 set explicitly to zero all the variables of G ′ other than i , z ,
to ensure correct behavior of G ′. Note that the w i are implicitly initialized to zero only the first time G ′ is executed. Clearly, f =
.
We have at once:
2.1.1.16 Proposition. If f, g, h relate as in Definition 2.1.1.14 and h and g are in
, then so is f. We say that
is closed under primitive recursion.
2.1.1.17 Example. (Unbounded Search) Suppose that
is partial computable, and, say, g =
. By earlier remarks we may assume that
and x are read-only in G and that z is not one of them.
Consider the following program F, where
is program G with the stop instruction removed, and instructions have been renumbered (and if-statements adjusted) as needed so that its first command has label 2.
1 : x ← 0
k : if z = 0 goto k + l + 3 else goto k + 1
k + 1 : w 1 ← 0 { Comment. Setting all non-input variables to 0; cf. 2.1.1.15. }
k + 1 : w 1 ← 0 { Comment. Setting all non-input variables to 0; cf. 2.1.1.15. }
k + l + 1 : x ← x + 1
k + l + 2 : goto 2
k + l + 3 : stop
Let us set
. Note that, for any
, f (
) ↓ precisely if the URM F, initialized with
as the input values in
ever reaches stop . This condition becomes true as long as the two conditions, (1) and (2) below, are fulfilled:
(1) Instruction k just found that z holds 0. This value of z is the result of an execution of G (i.e., G ′ with the stop instruction added) with input values
, in
and, say, b in x , the latter being the iteration counter —0, 1, 2, . . .—that indicates how many times instruction 2 becomes current.
(2) In none of the previous iterations (with x -value < b ) did G ′ (essentially, G ) get into a non-ending computation ( infinite loop ).
Correspondingly, the computation of F will never halt for an input
if either G loops for ever at some step, or, if it halts in every iteration b, but nevertheless it never exits with a z -value of 0.
Thus, for all
f (
) = min { x : g ( x ,
) = 0 ∧ (∀ y ) ( y < x → g ( y ,
) ↓ ) }
2.1.1.18 Definition. The operation on partial functions g given for all
by
min { x : g ( x ,
) = 0 ∧ (∀ y ) ( y < x → g ( y ,
) ↓ )}
is called unbounded search (along the variable x ) and is denoted by the symbol ( μx ) g ( x ,
). The function λ
.( μx ) g ( x ,
) is defined precisely when the minimum exists.
The result of Example 2.1.1.17 yields at once:
2.1.1.19 Proposition.
is closed under unbounded search; that is, if λ x
. g ( x ,
) is in
, then so is λ
.( μx ) g ( x ,
).
Why “unbounded” search? Because we do not know a priori how many times we have to go around the loop. This depends on the behavior of g .
2.1.1.20 Example. Is the function λ
n . x i , where 1 ≤ i ≤ n , in
? Yes, and here is a program, M, for it:
1 : w 1 ← 0
i : z ← w i { Comment. Cf. Exercise 2.1.1.10 }
n : w n ← 0
n + 1 : stop
λ
n . x i \=
. To ensure that M indeed has the w i as variables we reference them in instructions at least once, in any manner whatsoever.
2.1.2 Primitive Recursive Functions
Exercises 2.1.1.4 , 2.1.1.7, and 2.1.1.20 show that the successor, the zero, and the generalized identity functions respectively—which we will often name S, Z and
respectively—are in
; thus, not only are they “intuitively computable”, but they are so in a precise mathematical sense. We have also shown that “computability” of functions is preserved by the operations of composition, primitive recursion, and unbounded search. In this subsection we will explore the properties of the important set of functions known as primitive recursive. Most people introduce them by derivations just as one introduces the theorems of logic, as in the definition below.
Note that the “U” (u = unit) in
is suggested by the behavior of the function as the identity or unit function 54 that, essentially, takes x to x, but has additional “non active” or “don’t care” inputs. These unit functions are also called projection functions and are indeed the the
of Exercise 1.8.23 , but here we employ them in the special setting where A j \=
, for j = 1, ..., n . Unfortunately, the term “projection function” in computability clashes with the names of the specialized K and L functions associated with pairing functions (cf. 2.1.4.1 ).
2.1.2.1 Definition. (
-derivations;
-functions) A
-derivation is a finite sequence of number-theoretic functions that obeys, in its step-by-step construction, the following requirements. At each step we may write:
(1) Any one of Z, S,
(for any n > 0 and any 0 < i ≤ n ).
(2) λ
. f ( g 1 (
), ..., g n (
)), provided each of f, g 1 , ..., g n has already been written.
(3) prim ( h, g ), provided appropriate h and g have already been written. Note that h and g are “appropriate” (cf. 2.1.1.14 ) as long as g has two more arguments than h .
A function f is primitive recursive, or a
-function, iff it occurs in some
-derivation. The set of functions allowed in step (1) are called initial functions. We will denote this set by
. The set of all
-functions will be denoted by
.
2.1.2.2 Remark. The above definition defines essentially what Dedekind (1888) called “recursive” functions. Subsequently they have been renamed primitive recursive allowing the unqualified term recursive to be synonymous with computable and apply to the functions of
(cf. 2.1.1.2 ).
The concept of a
-derivation is entirely analogous with that of proof. Vis-à-vis proofs, derivations have the following analogous elements: initial functions (vs. axioms) and the operations composition and primitive recursion (vs. the rules of inference).
As it is the case with proofs, we can cut the tail off a derivation and still have a derivation. The reason is immediate: If the legitimacy of appearance of a function f in some
-derivation is based on (2) or (3) of 2.1.2.1 , then the presence or absence of the “tail” after f in said derivation is totally irrelevant to f ’s legitimacy of appearance. Thus, we deduce at once that a
-function is one that appears at the end of a
-derivation.
Properties of primitive recursive functions can be proved by induction on derivation length, just as properties of theorems can be proved by induction on the length of proofs.
That a certain function is primitive recursive can be proved by exhibiting a derivation for it, just as is done for the certification of a theorem: We exhibit a proof. However, in proving theorems we accept the use of known theorems in proofs. Similarly, if we know that certain functions are primitive recursive, then we immediately infer that so is one obtained from them by an allowed operation (composition, primitive recursion, or yet-to-be-introduced derived operations). For example, if h and g are in
and prim ( h, g ) makes sense according to 2.1.1.14 , then the latter is in
, too, since we can concatenate derivations of h and g and add prim ( h, g ) to the right end.
In analogy to the case of theorem proving, where we benefit from powerful derived rules, in the same way the certification of functions as primitive recursive is greatly facilitated by the introduction of derived operations on functions beyond the two that we assumed as given outright ( primary operations ) in Definition 2.1.2.1.
The reader will recognize at once that Definition 2.1.2.1 is a “concrete” or special instance of the abstract (or “general”) Definitions 1.6.0.6 and 1.6.0.9. Moreover, we must emphasize the fundamental (and practically important) relationship between iterative and recursive definitions of sets (cf. 1.6.0.14 ). The extremely useful principle of “ induction on (with respect to) a closure ” (or structural induction) is based, as the reader will recall from 1.6.0.13 , on the characterization of a set of objects as a closure. The earlier Remark 1.6.0.15 notes when we benefit from the iterative and when from the recursive point of view. It also provides an alternative reason for the correctness of the observation above:
Similarly, if we know that certain functions are primitive recursive, then we immediately infer that so is one obtained from them by an allowed operation . . .
Thus we may state at once:
2.1.2.3 Theorem.
is the closure of
under primitive recursion and composition .
2.1.2.4 Remark. (Induction over
) For the general principle, cf. 1.6.0.13 . We can do induction over
toward proving a property
for all f
. We prove:
(1) ( Basis ) All of Z, S,
(for any n > 0 and any 0, i ≤ n ) has the property
.
(2) λ
. f ( g 1 (
), ..., g n (
)) has the property, provided each of f, g 1 , ..., g n do.
(3) prim ( h, g ) has the property, provided h and g do.
The above procedure is more elegant (and more widely used) than induction on the length of
-derivation.
2.1.2.5 Example. If λ xyw.f ( x, y, w ) and λ z.g ( z ) are in
, how about λ xzw.f ( x, g ( z ), w )? It is in
since
λ xzw.f ( x, g ( z ), w ) = λ xzw.f (
( x, z, w ), g (
( x,z,w )),
( x, z, w ))
and the
are primitive recursive. The reader will see at once that to the right of “=” we have correctly formed compositions as expected by 2.1.1.13.
Similarly, for the same functions above,
(1) λ yw.f (2, y ,w ) is in
. Indeed, this function can be obtained by composition, since
λ yw.f (2, y, w ) = λ yw.f
SSZ (
( y, w )), y, w
where I wrote “ SSZ (. . .)” as short for S ( S ( Z (. . .))) for visual clarity. Clearly, using SSZ (
( y, w )) above works as well.
(2) λ xyw.f ( y, x, w ) is in
. Indeed, this function can be obtained by composition, since
λ xyw.f ( y, x, w ) = λ xyw.f
( x, y, w ),
( x, y, w ),
( x, y, w )
In this connection, note that while λ xy.g ( x, y ) = λ yx.g ( y, x ), yet λ xy.g ( x, y ) ≠ λ xy.g ( y, x ) in general. For example, λ xy.x
y asks that we subtract the second input ( y ) from the first ( x ), but λ xy.y
x asks that we subtract the first input ( x ) from the second ( y ).
(3) λ xy.f ( x, y, x ) is in
. Indeed, this function can be obtained by composition, since
λ xy.f ( x, y, x ) = λ xy.f (
( x, y ),
( x, y ),
( x, y ))
(4) λ xyzwu.f ( x, y, w ) is in
. Indeed, this function can be obtained by composition, since
The above examples are summarized, named, and generalized in the following straightforward exercise:
2.1.2.6 Exercise. (The Grzegorczyk (1953) Substitution Operations)
is closed under the following operations:
(i) Substitution of a function invocation for a variable :
From
and
obtain
.
(ii) Substitution of a constant for a variable :
From
obtain
.
(iii) Interchange of two variables :
From
obtain
.
(iv) Identification of two variables :
From
obtain
.
(v) Introduction of “don’t care” variables :
From
obtain
.
By 2.1.2.6 composition can simulate the Grzegorczyk operations if the initial functions
are present. Of course, (i) alone can in turn simulate composition. With these comments out of the way, we see that the “rigidity” of Definition 2.1.1.13 is gone.
2.1.2.7 Example. The definition of primitive recursion is also rigid, but this rigidity is removable as well. For example, natural and simple recursions such as p (0) = 0 and p ( x + 1) = x —this one defining p = λ x.x
1—do not fit the schema of Definition 2.1.1.14. This is because it requires the defined function to have one more variable than the basis, so no one-variable function can be directly defined! We can get around this. Define first
= λ xy.x
1 as follows:
(0, y ) = 0 and
( x + 1, y ) = x . Now this can be dressed up according to the syntax of the schema in 2.1.1.14 ,
(0, y ) = Z ( y )
( x + 1, y ) =
( x, y ,
( x, y ))
that is,
= prim ( Z ,
). Then we can get p by (Grzegorczyk) substitution: p = λ x .
( x , 0). Incidentally, this shows that both p and
are in
.
Another rigidity in the definition of primitive recursion is that, apparently, one can use only the first variable as the iterating variable. Consider, for example, sub = λ xy.x
y . Clearly, sub ( x , 0) = x and sub ( x, y + 1) = p ( sub ( x, y )) is correct semantically, but the format is wrong: We are not supposed to iterate along the second variable! Well, define instead
= λ xy.y
x :
Then, using variable swapping [Grzegorczyk operation (iii)], we can get sub : sub = λ xy .
( y, x ). Clearly, both
and sub are in
. With practice, one gets used to accepting at once simplified recursions like the one for p and sub. One needs to make them conform to the format of 2.1.1.14 only if the instructor insists!
2.1.2.8 Exercise. Prove that λ xy.x + y and λ xy.x × y are primitive recursive. Of course, we will usually write multiplication x × y in “implied notation”, xy .
2.1.2.9 Example. The very important “ switch ” (or “if-then-else)” function sw = λ xyz .if x = 0 then y else z is primitive recursive. It is directly obtained by primitive recursion on initial functions: sw (0, y, z ) = y and sw ( x + 1, y, z ) = z .
2.1.2.10 Exercise. Dress up the recursion sw (0, y, z ) = y and sw ( x + 1, y, z ) = z to bring it into the format required by Definition 2.1.1.14.
2.1.2.11 Exercise. Prove by induction first on derivation lengths, and then “over
”, that all functions in
are total.
2.1.2.12 Proposition.
⊆
.
Proof. By 2.1.1.12 , 2.1.1.16 , and 2.1.2.3 ,
⊆
. But all the functions in
are total (cf. 2.1.2.11 and Definition 2.1.1.2 ).
Indeed, the above inclusion is proper, as we will see in SubSection 2.4 . We also state for the record:
2.1.2.13 Proposition.
is closed under both composition and primitive recursion.
Proof Because
is, and both operations conserve totalness.
2.1.2.14 Example. Consider the function ex given by
ex ( x , 0) = 1
ex ( x, y + 1) = ex ( x, y ) x
Thus, if x = 0, then ex ( x , 0) = 1, but ex ( x, y ) = 0 for all y > 0. On the other hand, if x > 0, then ex ( x, y ) = x y for all y .
Note that x y is “mathematically” undefined when x = y = 0. 55 Thus, by Exercise 2.1.2.11 the exponential cannot be a primitive recursive function!
This is rather silly, since the computational process for the exponential is so straightforward; thus it is a shame to declare the function non-
. After all, we know exactly where and how it is undefined and we can remove this undefinability by redefining “ x y ” to mean ex ( x, y ) for all inputs.
Clearly ex
. In computability we do this kind of redefinition a lot in order to remove easily recognizable points of “non definition” of calculable functions. We will see further examples, such as the remainder, quotient, and logarithm functions.
Caution! We cannot always remove points of non definition of a calculable function and still obtain a computable function. That is, there are functions f
that have no recursive extensions. This we will show in SubSection 2.7 .
2.1.2.15 Definition. A relation R (
) is ( primitive ) recursive if its characteristic function ,
is (primitive) recursive. The set of all primitive recursive (respectively, recursive) relations is denoted by
* (respectively,
* ).
Computability theory practitioners often call relations predicates. It is clear that one can go from relation to characteristic function and back in a unique way, since R (
) ≡ χ R (
) = 0. Thus, we may think of relations as “0-1 valued” functions. The concept of relation simplifies the further development of the theory of primitive recursive functions.
The following is useful:
2.1.2.16 Proposition. R (
)
* iff some f
exists such that, for all
, R (
) ≡ f (
) = 0.
Proof . For the if -part, I want χ R
. This is so since χ R = λ
.1
(1
f (
)) (using Grzegorczyk substitution and λ xy.x
y
; cf. 2.1.2.7 ). For the only if -part, f = χ R will do.
2.1.2.17 Corollary. R (
)
* iff some f
exists such that, for all
, R (
) ≡ f (
) = 0.
Proof. By the above proof, 2.1.2.12 , and 2.1.2.13.
2.1.2.18 Corollary.
* ⊆
* .
Proof . By the above corollary and 2.1.2.12.
2.1.2.19 Theorem.
* is closed under the Boolean operations .
Proof. It suffices to look at the cases of ¬ and ⋁, since R → Q ≡ ¬ R ⋁ Q , R ⋀ Q ≡ ¬(¬ R ) ⋁ ¬ Q ) and R ≡ Q is short for ( R → Q ) ⋀ ( Q → P ).
(¬) Say, R (
)
* . Thus ( 2.1.2.15 ), χ R
. But then χ ¬ R
, since χ ¬ R \= λ
.1
χ R (
), by Grzegorczyk substitution and λ xy.x
y
.
(⋁) Let R (
)
* and Q (
)
* . Then
is given by
χ R ⋁ Q (
,
) = if R (
) then 0 else χ Q (
)
and therefore is in
.
2.1.2.20 Remark. Alternatively, for the ⋁ case above, note that χ R ⋁ Q (
,
) = χ R (
) × χ Q (
) and invoke 2.1.2.8.
It is common practice to use R (
) and χ R (
) (almost) interchangeably. For example, “if R (
) then . . .” is the same as “if χ R (
) = 0 then . . .”. The latter more directly shows that a (Grzegorczyk) substitution was effected into an argument of the if-then-else ( 2.1.2.9 ) function:
thus establishing the primitive recursiveness of the resulting function.
2.1.2.21 Corollary. R * is closed under the Boolean operations.
Proof . As above, mindful of 2.1.2.12 , and 2.1.2.13.
2.1.2.22 Example. The relations x ≤ y , x < y , x = y are in
* . See 2.1.1.5 for a refresher on our conventions regarding lambda notation and relations.
With this out of the way, note that x ≤ y ≡ x
y = 0 and invoke 2.1.2.16. Finally invoke Boolean closure and note that x < y ≡ ¬ y ≤ x while x = y is equivalent to x ≤ y ⋀ y ≤ x.
2.1.2.23 Proposition. If R (
, y ,
)
* and λ
. f (
)
, then R (
, f (
),
) is in
* .
Proof. Let Q (
,
,
) denote R (
, f (
),
). Then χ Q (
,
,
) = χ R (
, f (
),
).
2.1.2.24 Proposition. If R (
, y ,
)
* and λ
. f (
)
, then R (
, f (
),
) is in
* .
Proof. Similar to that of 2.1.2.23.
2.1.2.25 Corollary. If f
( respectively, in
), then its graph, z = f (
) is in
* (respectively, in
* ) .
Proof . Using the relation z = y and 2.1.2.23.
The following converse of 2.1.2.25 , “if z = f (
) is in
* and f is total, then f
” is not true. A counterexample is provided by the Ackermann function. However, “if z = f (
) is in
* and f is total, then f
” is true. More on the Ackermann function in Section 2.4 .
2.1.2.26 Exercise. Using unbounded search, prove that if z = f (
) is in
* and f is total, then f
.
2.1.2.27 Definition. (Bounded Quantifiers) The abbreviations (∀ y ) < z R ( z ,
) and (∃ y ) < z R ( z ,
) stand for (∀ y ) ( y < z → R ( z ,
)) and (∃ y ) ( y < z ⋀ R ( z ,
)), respectively, and similarly for the nonstrict inequality “≤”.
2.1.2.28 Theorem.
* is closed under bounded quantification.
Proof. By 2.1.2.19 it suffices to look at the case of (∃ y ) < z since (∀ y ) < z R ( y ,
) ≡ ¬(∃ y ) < z ¬ R ( y ,
).
Let then R ( y ,
)
* and let us give the name Q ( z ,
) to (∃ y ) < z R ( y ,
). We note that Q (0,
) is false (why?) and Q ( z + 1,
) ≡ Q ( z ,
) ⋁ R ( z ,
). Thus,
2.1.2.29 Corollary.
* is closed under bounded quantification.
2.1.2.30 Exercise. The operations of bounded summation and bounded multiplication are quite handy. These are applied on a function f and yield the functions
and
, respectively, where
and
by definition. Prove that
and
are closed under both operations; i.e., if f is in
(respectively, in
), then so are
and
.
2.1.2.31 Definition. (Bounded Search) Let f be a total number-theoretic function of n + 1 variables. The symbol ( μy ) < z f ( y ,
), for all z ,
, stands for
We define “( μy ) ≤ z ” to mean “( μy ) < z + 1 .
2.1.2.32 Theorem.
is closed under the bounded search operation ( μy ) < z . That is, if λ y
. f ( y ,
)
, then λ z
.( μy ) < z f ( y ,
)
.
Proof. Set g = λ z
.( μy ) < z f ( y ,
). Then the following primitive recursion settles it:
g (0,
) = 1
g ( z + 1,
) = if g ( z ,
) < z then g ( z ,
)
else if f ( z ,
) = 0 then z
else z + 1
2.1.2.33 Exercise. Mindful of the comment following 2.1.2.19 , dress up the primitive recursion that defined g above so that it conforms to the Definition 2.1.1.14.
2.1.2.34 Corollary.
is closed under the bounded search operation ( μy ) ≤ z .
2.1.2.35 Exercise. Prove the corollary.
2.1.2.36 Corollary.
is closed under the bounded search operations ( μy ) < z and ( μy ) ≤ z .
Consider now a set of mutually exclusive relations R i (
), i = 1, ..., n , that is, R i (
) ⋀ R j (
) is false for each
as long as i ≠ j .
Then we can define a function f by cases R i from given functions f j by the requirement (for all
) given below:
where, as is usual in mathematics, “if R j (
)” is short for “if R j (
) is true” and “otherwise” is the condition ¬( R 1 (
) ⋁ · · · ⋁ R n (
)). We have the following result:
2.1.2.37 Theorem. (Definition by Cases) If the functions f i , i = 1, ..., n + 1 and the relations R i (
), i = 1, ..., n are in
and
* , respectively, then so is f above.
Proof. By repeated use (composition) of if-then-else. Alternatively, by noting—being mindful of 2.1.2.19 —that
2.1.2.38 Corollary. Same statement as above, replacing
and
* by
and
* , respectively.
The tools we now have at our disposal allow easy certification of the primitive recursiveness of some very useful functions and relations. But first a definition:
2.1.2.39 Definition. ( μy ) < z R ( y ,
) means ( μy ) < z χ R ( y ,
).
Thus, if R ( y ,
)
* (resp.
* ), then λ z
.( μy ) < z R ( y ,
)
(resp.
R ), since χ R
(resp.
).
2.1.2.40 Example. The following are in
or
* as appropriate:
(1) λ xy. ⌊ x / y ⌋ 56 (the quotient of the division x / y ). This is another instance of a nontotal function with an “obvious” way to remove the points where it is undefined (cf. 2.1.2.14 ). Thus the symbol is extended to mean (μ, z ) ≤ x (( z +1) y > x ) for all x, y. It follows that, for y > 0, ⌊ x / y ⌋ is as expected in “normal math”, while ⌊ x /0⌋ = x + 1.
(2) λ xy.rem ( x, y ) (the remainder of the division x / y ). rem ( x, y ) = x
y ⌊ x / y ⌋.
(3) λ xy.x | y ( x divides y ). x | y ≡ rem ( y, x ) = 0. Note that if y > 0, we cannot have 0| y —a good thing!—since rem ( y , 0) = y. Our redefinition of ⌊ x/y ⌋ yields, however, 0|0, but we can live with this in practice.
(4) Pr ( x ) ( x is a prime). Pr ( x ) ≡ x > 1 ⋀ (∀ y ) ≤ x ( y | x → y = 1 ⋁ y = x ).
(5) π( x ) (the number of primes ≤ x ). 57 The following primitive recursion certifies the claim: π(0) = 0, and π( x + 1) = if Pr ( x + 1) then π ( x ) + 1 else π ( x ).
(6) λ n.p n (the n th prime). First note that the graph y = p n is primitive recursive: y = p n ≡ Pr ( y ) ⋀ π ( y ) = n + 1. Next note that, for all n , p n ≤ 2 2 n (see Exercise 2.1.2.42 below), thus p n \= ( μy ) ≤2 2 n ( y = p n ), which settles the claim.
(7) λ nx .exp( n, x ) ( the exponent of p n in the prime factorization of x ). exp( n, x ) =
.
(8) Seq ( x ) ( x ’s prime number factorization contains at least one prime, but no gaps) Seq ( x ) ≡ x > 1 ⋀ (∀ y ) ≤ x (∀ z ) ≤ x ( Pr ( y ) ⋀ Pr ( z ) ⋀ y < z ⋀ z | x → y | x ).
2.1.2.41 Remark. What makes exp( n, x ) “ the exponent of p n in the prime factorization of x ”, rather than an exponent, is Euclid’s prime number factorization theorem: Every number x > 1 has a unique factorization—within permutation of factors—as a product of primes. See Exercise 40 of Section 1.8.
2.1.2.42 Exercise. Prove by induction on n, that for all n we have p n ≤ 2 2 n .
Hint. Consider, as Euclid did, 58 p 0 p 1 · · · p n + 1. If this number is prime, then it is greater than or equal to p n + 1 (why?). If it is composite, then none of the primes up to p n divide it. So any prime factor of it is greater than or equal to p n + 1 (why?).
2.1.2.43 Exercise. Prove that λ x .⌊log 2 x ⌋
. Remove the undefinedness at x = 0 in some convenient manner. For example, arrange that ⌊log 2 0⌋ = 0
2.1.2.44 Definition. (Coding Sequences) Any sequence of numbers, a 0 , ..., a n , n ≥ 0, is coded by the number [ a 0 , ..., a n ] defined as
For coding to be useful, we need a simple decoding scheme. By Remark 2.1.2.41 there is no way to have z = [ a 0 , ..., a n ] = [ b 0 , ..., b m ], unless
(i) n = m
and
(ii) For i = 0, ..., n , a i \= b i .
Thus, it makes sense to correspondingly define the decoding expressions :
( i ) lh ( z ) (pronounced “length of z ”) as shorthand for ( μy ) ≥ z ¬( p y | z )
( ii ) ( z ) i as shorthand for exp( i, z )
1
Note that
(a) λ iz .( z ) i and λ z.lh ( z ) are in
.
(b) If Seq ( z ), then z = [ a 0 , ..., a n ] for some a 0 , ..., a n . In this case, lh ( z ) equals the number of distinct primes in the decomposition of z , that is, the length n + 1 of the coded sequence. Then ( z ) i , for i < lh ( z ), equals a i . For larger i , ( z ) i = 0. Note that if ¬ Seq ( z ) then lh ( z ) need not equal the number of distinct primes in the decomposition of z . For example, 10 has 2 primes, but lh (10) = 1.
The symbol [. . .] for numerical sequence coding is not standard. Usually,
. . .
is used in the literature on theory of computation. But this clashes with the use of the same symbol in set theory, used to denote ordered tuples of objects.
The tools lh, Seq ( z ), and λ iz .( z ) i are sufficient to perform decoding, primitive recursively, once the truth of Seq ( z ) is established. This coding/decoding scheme is essentially that of Gödel (1931), and we will use it throughout this volume.
We conclude this subsection with a flexible extension of primitive recursion on total functions. Simple primitive recursion defines a function “at n + 1” in terms of its value “at n ”. However we also have examples of “recursions” (or “recurrences”), one of the best known perhaps being the Fibonacci sequence, 0, 1, 1, 2, 3, 5, 8, ..., that is given by F 0 = 0, F 1 = 1 and (for n ≤ 1) F n + 1 = F n + F n −1 , where the value at n + 1 depends on both the values at n and n – 1. This generalizes to recursions where the value at n + 1 depends, in general, on the entire history, or course-of-values, of the function values at inputs n , n − 1, n − 2, ..., 1, 0. Cf. 1.7.0.29 . The easiest way to represent the history of values of a total number-theoretic function f “at (input) x ”, namely, { f (0,
), f (1,
), ..., f ( x ,
)}, is to code it by a single number!
2.1.2.45 Definition. (Course-of-Values Recursion) We say that f , of n + 1 arguments, is defined from two total functions—namely, the basis function λ
n . b (
n ) and the iterator λ x
n z.g ( x ,
n , z )—by course-of-values recursion if for all x ,
n the following equations hold:
where λ x
n . H ( x ,
n ) is the history function, which is given “at x ” (for all
n ) by
[ f (0,
), f (1,
), ..., f ( x ,
)]
Compare with the general case in 1.7.0.29 . Here, totalness allows a neat coding of the “history” { f (0,
), f (1,
, ..., f ( x ,
)} as a single number that depends on x and
. 59 Of course, 1.7.0.29 guarantees the existence of an f satisfying the schema (1) above.
2.1.2.46 Exercise. Prove that f given by (1) is total.
Hint. Use strong induction on x .
The major result here is:
2.1.2.47 Theorem.
is closed under course-of-values recursion .
Proof. So, let b and g be in
. We will show that f
. It suffices to prove that the history function H is primitive recursive, for then f = λ x
n .( H ( x ,
n )) x and we are done by Grzegorczyk substitution. To this end, the following equations—true for all x ,
n —settle the case:
The same proof with trivial adjustments yields:
2.1.2.48 Corollary.
is closed under course-of-values recursion.
2.1.2.49 Example. The Fibonacci sequence, ( F n ) n ≥0 , is given by
F 0 = 0
F 1 = 1
otherwise,
F n +1 \= F n + F n −1
It can be viewed as a function λ n . F n . As such it is in
. Indeed, letting H n be the history of the sequence at n —that is, [ F 0 , ..., F n ]—we have the following course-of-values recursion for λ n.F n in terms of functions known to be in
.
F 0 = 0
F n +1 \= if n = 0 then 1
else ( H n ) n + ( H n ) n
1
2.1.2.50 Remark. How important is totalness in course-of-values recursion?
Let us analyze the primitive recursion schema below, where b and g are known to be in
. What can we learn from the partial recursive H that is defined as follows? (Note the use of “≃” this time.)
First off, the domain of λ x.H ( x ,
n is either
, or a set of the form { i
: i < k } for some k (that depends on the chosen fixed
n ). We call this latter set an initial segment of
.
Let us verify this claim. We fix a
n . If λ x.H ( x,
n ) is total, then there is nothing to prove. Otherwise, let x = x 0 be smallest such that H ( x,
n ) ↑. By induction on x we see that H ( x,
n ) ↑, for x ≥ x 0 . Indeed, the basis is from the choice of x 0 . On the obvious I.H. let us look at H ( x + 1,
n . By the I.H., the product in the right hand side of (1) is undefined.
Next, we note that “if x < x 0 then H ( x,
n ) = [ a 0 , ..., a x ], for appropriate a i ”. Of course, if x 0 = 0 then the statement is vacuously true. So assume x 0 > 0. We do induction on x. The basis is settled by H (0,
n ) = [ b (
n )] (why “=”?). If H ( x ,
n ) = [ a 0 , · · · , a x ] and x + 1 < x 0 ( I.H. ), then the second equation of (1) yields H ( x + 1,
n ) = [ a 0 , ..., a x , g ( x ,
, H ( x ,
))], as needed.
Let us now set
Thus we have the validity of the course-of-values recurrence, for all x and
n
By (2) and the earlier remarks, dom( f ) = dom( H ) and in particular, for each fixed
n , dom(λ x.f ( x ,
n )) is either
or a set of the form { i
: i < k } for some k (that depends on the chosen fixed
n ).
By definition, (1) is the course-of-values recursion schema for partial functions. It defines a function H, but also a function f, the latter satisfying (3). We can now summarize:
2.1.2.51 Theorem.
is closed under the schema of course-of-values recursion, that is, (1) of 2.1.2.50. For any fixed
_n , the subsidiary function f defined by (2) is either total in x or is an initial segment of
. _Moreover it satisfies the recursion (3).
2.1.3 Simultaneous Primitive Recursion
Taking B =
k in 1.7.0.27 , and letting h and g be total functions from
n and
n +1 ×
k respectively to
k , and replacing ≃ by =, (1) in said example becomes
Now f, h, and g are k -tuple valued, so they are not number-theoretic functions (which must have a right field equal to
, by definition; cf. 2.1.1.6 ). However, if we write them in terms of their components, for example,
f ( x ,
n ) =
f 1 ( x ,
n ), ..., f k ( x ,
n )
then we can rewrite the recurrence equations (1) componentwise, to obtain the schema of simultaneous (primitive) recursion below, which first occurred in Hilbert and Bernays (1968).
Hilbert and Bernays proved the following:
2.1.3.1 Theorem. If all the h i and g i are in
(resp.
), then so are all the f i obtained by the schema (2) of simultaneous recursion.
Proof. Define, for all x,
n , and
k ,
We readily have that H
(resp.
) and G
(resp.
)—and, in particular, λ x
n z.G ( x ,
n , ( z ) 0 , ..., ( z ) k −1 )
(resp.
)—depending on where we assumed the h i and g i to be. We can now rewrite schema (2) as
By the above remarks, F
(resp.
) depending on where we assumed the h i and g i to be. In particular, this holds for each f i since, for all x ,
n , f i ( x ,
n ) = ( F ( x ,
n )) i −1 .
2.1.3.2 Example. We saw one way to justify that λ x.rem ( x , 2)
in 2.1.2.40. A direct way is the following. Setting f ( x ) = rem ( x , 2), for all x , we notice that the sequence of outputs (for x = 0, 1, 2, . . .) of f is
0, 1, 0, 1, 0, 1 . . .
Thus, the following primitive recursion shows that f
:
Here is a way, via simultaneous recursion, to obtain a proof that f
, without using any arithmetic! Notice the infinite “matrix”
0 1 0 1 0 1 . . .
1 0 1 0 1 0 . . .
Let us call g the function that has as its sequence outputs the entries of the second row—obtained by shifting the first row by one position to the left. The first row still represents our f. Now
The reader may protest that the above example contains a bit of an overstatement, if not sophistry: After all, to legitimize simultaneous recursion as a “
operation” not only did we use arithmetic, but quite a bit at that. Didn’t we?
Well yes, but that is irrelevant to the point we are driving at: A very simple programming language (formalism), which we will discuss in the next section, is intimately connected with simultaneous recursion, and we will see that, within that formalism, we indeed can compute rem ( x , 2) doing no arithmetic at all!
How we will do this is precisely reflected by the recursion (1) above.
2.1.3.3 Example. We saw one way to justify that λ x . ⌊ x /2⌋
in 2.1.2.40. A direct way is the following.
where rem is in
by 2.1.2.40 or by 2.1.3.2.
Alternatively, here is a way that can do it—via simultaneous recursion—and with only the knowledge of how to add 1. Consider the matrix
0 0 1 1 2 2 3 3 . . .
0 1 1 2 2 3 3 4 . . .
The top row represents λ x . ⌊ x /2⌋, let us call it “ f ”. The bottom row we call g and is, again, the result of shifting row one to the left by one position. Thus, we have a simultaneous recursion
2.1.4 Pairing Functions
Coding of sequences a 0 , a 1 , ..., a n , for n ≥ 1, has a special case; pairing functions, that is, the case of n = 2.
2.1.4.1 Definition. A total, 1-1 function J :
×
→
is called a pairing function.
2.1.4.2 Remark. By 1.2.0.25 there is an onto g :
→
×
such that g ( J ( x , y )) =
x , y
for all x , y in
. g is pair-valued (“vector”-valued) thus not a number-theoretic function. As in the previous subsection, we may write, for all z
dom ( g ),
g ( z ) =
K ( z ), L ( z )
that is, decompose g as a pair of functions
K , L
along the “ x -” and “ y -axes”. We call K and L the first and second projection functions of the pairing function f, respectively. We have at once, for all x and y in
,
and
One usually encounters the (capital) letters K, L in the literature as (generic) names for projection functions of some (generic) pairing function. In turn, the generic symbol for the latter is J rather than “ f ”. We will conform to this notational convention in what follows.
We must emphasize that since Definition 2.1.4.1 does not require a pairing function J to be onto
, we cannot expect
to hold in general. In fact, (3) requires that J is onto (cf. 1.2.0.22 ).
Pause. What if in (3) we said “for all z
dom (
K , L
)” instead?
Hint. See Section 1.8 , Exercise 26 .
Also note that if the g of this remark is obtained precisely as in 1.2.0.25 , then its domain equals the range of J —cf. 1.2.0.26 . However, we can extend g to a total function
, for example, letting, for all z
,
Clearly, we still get (
J ) = 1
, that is,
( J ( x, y )) =
x , y
for all x and y in
, simply because J ( x, y )
dom( g ). Of course, by preceding remarks, ( J
) = 1
must fail unless J is onto
.
The set of “tools” consisting of a pairing function J and its two projections K and L is a coding/decoding scheme for sequences of length two. We want to have computable such schemes and indeed there is an abundance of primitive recursive pairing functions that also have primitive recursive projections. Some of those we will indicate in the examples below and others we will let the reader to discover in the exercises section.
2.1.4.3 Example. The function J = λ xy . [ x, y ] is pairing. Its projections are K = λ z . ( z ) 0 and L = λ z . ( z ) 1 . All three are already known to us as members of
.
This J is not onto. For example, 5
ran( J ). Nevertheless, K and L are total—because λ iz . ( z ) i is; indeed is in
—and unlike the explicit extension of g in the preceding remark, this fact did not require our intervention.
Pause. Does the coincidence of the non ontoness of the J above, and the totalness of K and L, contradict our calculation in 1.2.0.26 ?
2.1.4.4 Example. The function J = λ xy .2 x 3 y is pairing. Its projections are K = λ z . exp(0, z ) and L = λ z . exp(1, z ) (cf. 2.1.2.40 ). All three are already known to us as members of
.
This J is not onto. Again, 5
ran( J ). Nevertheless, K and L are total—because λ iz . exp ( i, z ) is; indeed is in
—and unlike the explicit extension of g in the preceding remark, this fact did not require our intervention either.
Clearly, for any distinct primes p i and p j , the function
is pairing, with projections λ z . exp ( i, z ) and λ z . exp ( j, z ).
2.1.4.5 Example. Note that every number n ≥ 1 has a unique representation—i.e., the x and y are uniquely determined by n —of the form 2 x (2 y + 1). This, for n ≥ 2 is just an abstraction of the unique factorization theorem, recognizing that the 3 a 5 a ′ 7 a ″ · · · part of the factorization is an odd number. On the other hand, 1 = 2 0 (2 · 0 + 1).
Thus, the J = λ xy .2 x (2 y + 1) of Grzegorczyk (1953) is pairing. This J is not onto either; it just misses one member of
!
Its projections can be easily calculated in a manner that readily establishes their primitive recursiveness. K z \= exp (0, z ) and
The preceding example illustrates a notational convention that we will adhere to regarding projection functions: We will write “ K z ”, “ L z ”, “ K LLz ”, etc., omitting brackets from around arguments. This is a visual improvement over “ K(z) ”, “ L(z) ”, “ K ( L ( L ( z )))”, etc.
2.1.4.6 Example. J = λ xy .2 x + y +2 + 2 y +1 is pairing. That it is in
and hence total is trivial. Why is it 1-1? Well, we may prove this directly, but instead, what if I can find x and y uniquely in terms of z once I set z = 2 x + y +2 + 2 y +1 ?
If that succeeds then I have defined two functions λ z.K z and λ z.L z that satisfy (1) and (2) of 2.1.4.2. This will prove that J is 1-1 by 1.2.0.22 !
Let us do this, and start by setting z = J ( x, y ). We will “solve” for (natural number-values of) x and y : 60 Notice that 2 y +1 < 2 x+y +2 , 61 hence, 2 x+y +2 ≤ z < 2 x+y +2 + 2 x+y +2 \= 2 x+y +3 . Thus, taking logarithms base-2, x + y + 2 ≤ log 2 z < x + y + 3. We obtain at once
Now, z = 2 ⌊log 2 z ⌋ + 2 y+2 , thus
We obtain L z \= ⌊log 2 ( z
2 ⌊log 2 z ⌋ )⌋
1 and, from (1), K z \= ⌊log 2 z ⌋
( Lz + 2). From Exercise 2.1.2.43 we conclude that K and L are indeed in
.
2.1.4.7 Example. In 2.1.4.6 we note that J ( x, y ) ≥ x and J ( x, y ) ≥ y , for all x, y . Thus an alternative way to prove that the related K and L are in
is to compute as follows:
and
Equipped with theorems 2.1.2.28 and 2.1.2.32 , and Definition 2.1.2.39 , we see that (1) and (2) establish that K and L are in
.
But this approach—unlike that in the preceding example—does not prove that K and L exist or that the J is 1-1!
Pause. Why?
2.1.4.8 Example. Here is a pairing function that does not require exponentiation. Let J ( x , y ) = ( x + y ) 2 + x . Clearly, J
.
Let us use the methodology of 2.1.4.6. So let us set z = ( x + y ) 2 + x and solve this “equation” for x and y (uniquely, hopefully). Well, ( x + y ) 2 ≤ z < ( x + y + 1) 2 . Thus
, hence
Then,
and therefore
. By (1),
As in 2.1.4.7 , the J here satisfies J ( x , y ) ≥ x and J ( x , y ) ≥ y . Thus, if we have an independent proof of the existence of K and L (say, by proving directly that J is 1-1; cf. Exercise 4 in Section 2.12 ), then their primitive recursiveness follows from the calculations
and
Why bother about pairing functions when we have the coding of sequences scheme of the previous subsection? Because prime-power coding is computationally very inefficient, while quadratic schemes such as that of the previous example allow us to significantly reduce the “computational complexity” of coding/decoding. But can we code arbitrary length sequences efficiently?
Yes, because any J , K , L scheme can lead to a coding/decoding scheme for sequences a 1 , . . ., a n , n ≥ 2, for both the cases of a fixed or variable n .
2.1.4.9 Definition. Given a primitive recursive pairing scheme J , K , L .
For any fixed n ≥ 2 we define by recursion on n the symbol
:
and
.
2.1.4.10 Remark. It is a trivial exercise to verify that the 1-1 ness of J implies that of
, for any n ≥ 2. Moreover, if J is onto
, then so is
(cf. Exercise 34 in Section 1.8 ).
The primitive recursive K and L give rise to primitive recursive projections, denoted by
for each fixed n , and each 1 ≤ i ≤ n .
These will satisfy
= y i , for 1 ≤ i ≤ n .
The Π are defined by composition from K and L as follows (cf. Exercise 8 in Section 2.12 ). if
, then
where we wrote L i for
for any fixed i ( i – 1 compositions with itself).
We can also effect coding of variable length sequences, starting with a J , K , L primitive recursive scheme. However, we will not take this approach in this volume. Here is how:
2.1.4.11 Definition. Given a primitive recursive pairing scheme J , K , L with a J that is onto.
A sequence a 1 , ..., a n , n ≥ 0—n = 0 denoting the empty sequence—is coded by the expression
if n = 0;
if n = 1; and
otherwise. We denote by lg ( z ) the sequence length, thus we set lg = K .
Ontones of J, and hence of
, for any n ≥ 2, ensures that every z is a valid “code”, so it makes sense to decode it once we know the code’s length ; we do not need a predicate analogous to “Seq” ( Example 2.1.2.40 , item 8).
The projections, denoted by
, for non zero lg ( z ) and 1 ≤ i ≤ lg ( z ), are
The reader encounters here the symbol “ L i ”, where i is variable (an input), for the first time. What does it mean, and is λ iz . L i ( z ) primitive recursive?
This is a special case of primitive recursion, known as iteration (composing a function with itself a “variable number of times”), a concept that we will take up in the next subsection. In the present case we note that
L 0 z = z
L x +1 z = L ( L x z )
Brackets were inserted in “ LL x z ” above to make the iterator ( 2.1.1.14 ) “ L (. . .)” stand out. The above primitive recursion shows that λ iz . L i z
.
2.1.5 Iteration
A very natural special case of primitive recursion, that of composing a function with itself a number of times that is “read” as an input—a “variable number of times”—has been studied by Robinson (1947) in the context of number-theoretic functions. In general, if g : A → A is some function, its (pure) iteration is the function λ xy · g x ( y ) :
× A → A given by the following definition:
2.1.5.1 Definition. (Pure Iteration) We say that λ xy · f ( x , y ) :
× A → A — where A is some set—is defined from λ x · g ( x ) : A → A by pure iteration iff, for all x
and y
A , we have
f (0, y ) = y
f ( x + 1, y ) ≃ g ( f ( x,y ))
We write g x ( y ) for f ( x , y ), since a trivial induction on k shows that, for any k
, f ( k , y ) ≃
, while we adhere to the convention that g 0 = 1 A .
2.1.5.2 Remark. Of course, we replace ≃ above by = if g is total. Thus every iteration is a special case of primitive recursion in the style of 2.1.1.14. Indeed, for any g
, λ xy · g x ( y )
.
2.1.5.3 Example. Let g :
×
→
×
be given by g ( x , y ) =
y , x
. What is g z (0, 1)? It is
rem ( z , 2), rem ( z + 1, 2)
. Cf. Example 2.1.3.2.
2.1.5.4 Example. Let g :
×
→
×
be given by g ( x , y ) =
y , x + 1
. What is g z (0, 0)? Consider the diagram below that indicates the values of g 0 , g 1 g 2 , g 3 , . . . starting at input
0, 0
(depicted as
below). The arrows, labeled g , indicate the input/output relation of g applied to the input at the left of the arrow in each case.
Thus, g z (0,0) =
Cf. Example 2.1.3.3 .
2.1.5.5 Example. Let g : A n → A n be such that its first component is the “identity” function, in the sense,
for all
a , . . .
dom( g ) (cf. Exercise 1.8.23 ). In other words, if g =
g 1 . . . , g n
is the decomposition of g into its components, then g 1 (
) = x 1 for all
in its domain.
We will show that the first component of
is also the identity.
Indeed, we can show this by induction on z : For z = 0, g 0 (
) =
, hence
, for all
. For fixed z , assume (I.H.) that
, for all
on which the left hand side of = is defined (*)
that is, g z (
) =
x 1 , . . .
. Thus,
g z +1 (
) = g ( x 1 , . . .) = 62
x 1 , g 2 (
x 1 , . . .
), . . ., g n (
x 1 , . . .
)
2.1.5.6 Remark. The preceding result clearly holds in the special cases on the two extremes:
(1) The induction step above essentially proves that if the first component of each of g : A n → A n and f : A n → A n is the identity, then this holds for ( f g ) and ( g f ) as well . Indeed, all that we used about g z in the I.S. above was (*); we might as well think of λ
. g z (
) as the “f” here.
(2) With g as in 2.1.5.5 , let us set f = λ
z · g z (
). Then f (
, z ) =
x 1 , . . .
whenever it is defined.
It is clear from the arguments presented here and in 2.1.5.5 that x 1 , the “first” variable, is not particularly privileged with respect to the foregoing reasoning, and that the results hold no matter which component of g and f is the identity. The “general” case starts with g =
g 1 , ..., g n
[and f =
f 1 , ..., f n
in (1)], where g k (
) = x k [and f k (
) = x k in (1)], for all
in the respective domains.
The main result in this subsection is Robinson’s theorem, that in the presence of pairing functions we have a converse of Remark 2.1.5.2 : that iteration can simulate primitive recursion of number-theoretic functions.
2.1.5.7 Theorem. If a class of total number-theoretic functions is closed under iteration and composition and includes a pairing scheme J, K, L, then it is closed under the full primitive recursion of 2.1.1.14 as well.
Proof . We follow Tourlakis (1984). We are given the number-theoretic g (iterator) and h (basis). We will simulate the schema ( A ) below, using pure iteration.
Using the coding introduced in Definition 2.1.4.9 that is generated by the given here J , K , L , we define the function F by
We may write a primitive recursion for F :
Noting that (omitting bracketing)
, for 1 ≤ i ≤ n ; and
we see that schema ( B ) has the form
where
and
A trivial induction on x shows that F ( x ,
) = G x H (
). Thus, we have reduced the schema ( A ) to pure iteration G x and composition and can obtain f as the ( n + 2)-th projection of F , as already indicated.
( x , y )—where the input variables are all the free variables, here x and y —in the case of relations we are allowed two points of view; one being the one presented above, and the other where both x and y are the inputs of the relation R ( x , y ). The context will fend for us!