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( images , images )—cf. Section 1.6. To do so we start with some set of initial functions images that are immediately recognizable as “intuitively computable”, and choose a set images 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( images , images ) 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

images

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 images . 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:

images

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:

images

where L, M, R, a, written in decimal notation, are in images , 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 images 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.

images    This command is syntactically illegal (meaningless) if any of M or R exceed the label of the program’s stop instruction.   images

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 : images n → images 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 images :

(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 ). images

images    (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 images . 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 images are “apparent”, or not free for substitution, since images 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, images , 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 = images , but not f ( a 1 , ..., a n ) = images .

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, images 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.   images

2.1.1.2 Definition. (Computable Functions) A function f : images n → images of n variables x 1 , ..., x n is called partial computable iff for some URM, M, we have f = images . The set of all partial computable functions is denoted by images . The set of all the total functions in images —that is, those that are defined on all inputs from images —is the set of computable functions and is denoted by images . The term recursive is used in the literature synonymously with the term computable. images

images    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)].   images

2.1.1.4 Example. Let M be the program

         1 : x ← x + 1

2 : stop

Then images is the function f given, for all x Images images , by f ( x ) = x + 1, the successor function. images

2.1.1.5 Remark. ( λ Notation) To avoid saying verbose things such as “ images is the function f given, for all x Images images , by f ( x ) = x + 1”, we will often use Church’s λ-notation and write instead “ images = λ 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? images

Because well-chosen notation protects against meaningless statements, such as

images

that one might make in the context of the above example. As remarked before, “ images ” is not a term, nor are the occurrences of x in it free (for substitution). For example, “ images = 4” [obtained by substituting 3 for x throughout in (1)] is totally meaningless, as it says

images

However, images = λ 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

images

In programming circles, the distinction between function definition or declaration, λ images . f ( images ), and function invocation (or call, or application, or “use”)—what we call a term, f ( images ), 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 ( images 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 ( images n )”, by convention, is short for stating “ images images n images ” Images R ”, we have two notations for a relation: Logical or relational, i.e., R ( images n ), and set-theoretic, i.e., images images n images Images 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 images ) 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. images

images    We wrote on p. 41

Thus, the relation (table) establishes a one-to-many input/output correspondence. Contrary to our viewpoint with formulae images ( 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

images

with n − 1 input-variables and one output variable, but rather as formulae R ( images 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 images ) 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 ”.   images

2.1.1.6 Example. Let M be the program

         1 : x ← x images 1

2 : stop

Then images is the function λ x . x images 1, the predecessor function. The operation images is called “proper subtraction” and is in general defined by

images

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 images and outputs in images . images

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? images

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 images is the function λ x .0, the zero function . images

images    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.    images

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 ′. images

2.1.1.9 Example. Let M be the program segment

k – 1 : x ← 0
       k :        x ← x + 1
      k + 1 : z ← z images 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. images

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. images

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, images = images , and M ′ does not change x ′.

2.1.1.11 Example. (Composing Computable Functions) Suppose that λ x images . f ( x , images ) and λ images . g ( images ) are partial computable, and say f = images while g = images .

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, images . 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. images

Thus, we have, by repeating the above a finite number of times:

2.1.1.12 Proposition. If λ images n . f ( Images n ) and λ images . g i ( Images ), for i = 1, ..., n, are partial computable, then so is images .

We can rephrase 2.1.1.12 , saying simply that images 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) λ images n . f ( Images n ) and λ images . g i ( Images ), for i = 1, ..., n, we say that images is the result of their composition. images

images    We characterized the definition as “rigid”. Indeed, note that it requires all the arguments of f to be substituted by some g i ( images )—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 images —and for each application g i (. . .) the argument list, “. . .”, must be the same, for example images . 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 : images n → images and the n -tuple-valued function images g 1 , ..., g n images : images m → images n 53 and form images g 1 , ..., g n images Images f .

As we will show in examples in the next subsection ( 2.1.2 ), this rigidity is only apparent.   images

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 images and images provided, for all x , images , its values are given by the two equations below:

images

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). images

Note that images images , 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 images and λ images . h ( images ) are partial computable, and, say, images while images .

By earlier remarks we may assume:

(i) The only variables that H and G have in common are z , images .

(ii) The variables images 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 images is program H with the stop instruction removed, images is program G that has the stop instruction removed, and instructions renumbered (and if-statements adjusted) as needed:

       images
r :         i ← 0    
                                               r + 1 :   if x = 0 goto k + m + 2 else goto r + 2
    r + 2 :   x ← x images 1
       images
  k :         i ← i + 1
k + 1 :   w 1 ← 0  
images                         
  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 , images 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 = images . images

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 images , then so is f. We say that images is closed under primitive recursion.

2.1.1.17 Example. (Unbounded Search) Suppose that images is partial computable, and, say, g = images . By earlier remarks we may assume that images and x are read-only in G and that z is not one of them.

Consider the following program F, where images 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
             images
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. }
images
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 images . Note that, for any images , f ( images ) ↓ precisely if the URM F, initialized with images as the input values in images 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 images , in images 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 images 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 images

f ( images ) = min { x : g ( x , images ) = 0 ∧ (∀ y ) ( y < x → g ( y , images ) ↓ ) } images

2.1.1.18 Definition. The operation on partial functions g given for all images by

min { x : g ( x , images ) = 0 ∧ (∀ y ) ( y < x → g ( y , images ) ↓ )}

is called unbounded search (along the variable x ) and is denoted by the symbol ( μx ) g ( x , images ). The function λ images .( μx ) g ( x , images ) is defined precisely when the minimum exists. images

The result of Example 2.1.1.17 yields at once:

2.1.1.19 Proposition. images is closed under unbounded search; that is, if λ x images . g ( x , images ) is in images , then so is λ images .( μx ) g ( x , images ).

images    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 .   images

2.1.1.20 Example. Is the function λ images n . x i , where 1 ≤ i ≤ n , in images ? Yes, and here is a program, M, for it:

1 :         w 1 ← 0  

images                         

                                                       i :          z ← w i { Comment. Cf. Exercise 2.1.1.10 }

images                          

n :       w n ← 0   

n + 1 : stop           

λ images n . x i \= images . To ensure that M indeed has the w i as variables we reference them in instructions at least once, in any manner whatsoever. images

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 images respectively—are in images ; 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.

images    Note that the “U” (u = unit) in images 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 images of Exercise 1.8.23 , but here we employ them in the special setting where A j \= images , 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 ).   images

2.1.2.1 Definition. ( images -derivations; images -functions) A images -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, images (for any n > 0 and any 0 < i ≤ n ).

(2) λ images . f ( g 1 ( images ), ..., g n ( images )), 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 images -function, iff it occurs in some images -derivation. The set of functions allowed in step (1) are called initial functions. We will denote this set by images . The set of all images -functions will be denoted by images . images

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 images (cf. 2.1.1.2 ).

The concept of a images -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 images -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 images -function is one that appears at the end of a images -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 images and prim ( h, g ) makes sense according to 2.1.1.14 , then the latter is in images , 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. images

images    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:   images

2.1.2.3 Theorem. images is the closure of images under primitive recursion and composition .

images    2.1.2.4 Remark. (Induction over images ) For the general principle, cf. 1.6.0.13 . We can do induction over images toward proving a property images for all f Images images . We prove:

(1) ( Basis ) All of Z, S, images (for any n > 0 and any 0, i ≤ n ) has the property images .

(2) λ images . f ( g 1 ( images ), ..., g n ( images )) 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 images -derivation.   images

2.1.2.5 Example. If λ xyw.f ( x, y, w ) and λ z.g ( z ) are in images , how about λ xzw.f ( x, g ( z ), w )? It is in images since

λ xzw.f ( x, g ( z ), w ) = λ xzw.f ( images ( x, z, w ), g ( images ( x,z,w )), images ( x, z, w ))

and the images 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 images . Indeed, this function can be obtained by composition, since

λ yw.f (2, y, w ) = λ yw.f Images SSZ ( images ( y, w )), y, w Images

where I wrote “ SSZ (. . .)” as short for S ( S ( Z (. . .))) for visual clarity. Clearly, using SSZ ( images ( y, w )) above works as well.

(2) λ xyw.f ( y, x, w ) is in images . Indeed, this function can be obtained by composition, since

λ xyw.f ( y, x, w ) = λ xyw.f images images ( x, y, w ), images ( x, y, w ), images ( x, y, w ) images

images    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 images y asks that we subtract the second input ( y ) from the first ( x ), but λ xy.y images x asks that we subtract the first input ( x ) from the second ( y ).   images

(3) λ xy.f ( x, y, x ) is in images . Indeed, this function can be obtained by composition, since

λ xy.f ( x, y, x ) = λ xy.f ( images ( x, y ), images ( x, y ), images ( x, y ))

(4) λ xyzwu.f ( x, y, w ) is in images . Indeed, this function can be obtained by composition, since

images images

The above examples are summarized, named, and generalized in the following straightforward exercise:

2.1.2.6 Exercise. (The Grzegorczyk (1953) Substitution Operations) images is closed under the following operations:

(i) Substitution of a function invocation for a variable :
From images and images obtain images .

(ii) Substitution of a constant for a variable :
From images obtain images .

(iii) Interchange of two variables :
From images obtain images .

(iv) Identification of two variables :
From images obtain images .

(v) Introduction of “don’t care” variables :
From images obtain images . images

By 2.1.2.6 composition can simulate the Grzegorczyk operations if the initial functions images 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 images 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 images = λ xy.x images 1 as follows: images (0, y ) = 0 and images ( x + 1, y ) = x . Now this can be dressed up according to the syntax of the schema in 2.1.1.14 ,

images (0, y )       = Z ( y )
                   images ( x + 1, y ) = images ( x, y , images ( x, y ))

that is, images = prim ( Z , images ). Then we can get p by (Grzegorczyk) substitution: p = λ x . images ( x , 0). Incidentally, this shows that both p and images are in images .

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 images 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 images = λ xy.y images x :

images

Then, using variable swapping [Grzegorczyk operation (iii)], we can get sub : sub = λ xy . images ( y, x ). Clearly, both images and sub are in images . 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! images

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 . images

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 . images

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. images

2.1.2.11 Exercise. Prove by induction first on derivation lengths, and then “over images ”, that all functions in images are total. images

2.1.2.12 Proposition. images ⊆ images .

Proof. By 2.1.1.12 , 2.1.1.16 , and 2.1.2.3 , images ⊆ images . But all the functions in images are total (cf. 2.1.2.11 and Definition 2.1.1.2 ). images

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. images is closed under both composition and primitive recursion.

Proof Because images is, and both operations conserve totalness. images

images    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- images . 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 Images images . 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 Images images that have no recursive extensions. This we will show in SubSection 2.7 .   images

2.1.2.15 Definition. A relation R ( images ) is ( primitive ) recursive if its characteristic function ,

images

is (primitive) recursive. The set of all primitive recursive (respectively, recursive) relations is denoted by images * (respectively, images * ). images

images    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 ( images ) ≡ χ R ( images ) = 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.   images

The following is useful:

2.1.2.16 Proposition. R ( images ) Images images * iff some f Images images exists such that, for all images , R ( images ) ≡ f ( images ) = 0.

Proof . For the if -part, I want χ R Images images . This is so since χ R = λ images .1 images (1 images f ( images )) (using Grzegorczyk substitution and λ xy.x images y Images images ; cf. 2.1.2.7 ). For the only if -part, f = χ R will do. images

2.1.2.17 Corollary. R ( images ) Images images * iff some f Images images exists such that, for all images , R ( images ) ≡ f ( images ) = 0.

Proof. By the above proof, 2.1.2.12 , and 2.1.2.13. images

2.1.2.18 Corollary. images * ⊆ images * .

Proof . By the above corollary and 2.1.2.12. images

2.1.2.19 Theorem. images * 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 ( images ) Images images * . Thus ( 2.1.2.15 ), χ R Images images . But then χ ¬ R Images images , since χ ¬ R \= λ images .1 images χ R ( images ), by Grzegorczyk substitution and λ xy.x images y Images images .

(⋁) Let R ( images ) Images images * and Q ( images ) Images images * . Then images is given by

χ R ⋁ Q ( images , images ) = if R ( images ) then 0 else χ Q ( images )

and therefore is in images . images

2.1.2.20 Remark. Alternatively, for the ⋁ case above, note that χ R ⋁ Q ( images , images ) = χ R ( images ) × χ Q ( images ) and invoke 2.1.2.8. images

images    It is common practice to use R ( images ) and χ R ( images ) (almost) interchangeably. For example, “if R ( images ) then . . .” is the same as “if χ R ( images ) = 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:

images

thus establishing the primitive recursiveness of the resulting function.   images

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. images

images    2.1.2.22 Example. The relations x ≤ y , x < y , x = y are in images * . 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 images 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.    images

2.1.2.23 Proposition. If R ( images , y , images ) Images images * and λ images . f ( images ) Images images , then R ( images , f ( images ), images ) is in images * .

Proof. Let Q ( images , images , images ) denote R ( images , f ( images ), images ). Then χ Q ( images , images , images ) = χ R ( images , f ( images ), images ). images

2.1.2.24 Proposition. If R ( images , y , images ) Images images * and λ images . f ( images ) Images images , then R ( images , f ( images ), images ) is in images * .

Proof. Similar to that of 2.1.2.23. images

2.1.2.25 Corollary. If f Images images ( respectively, in images ), then its graph, z = f ( images ) is in images * (respectively, in images * ) .

Proof . Using the relation z = y and 2.1.2.23. images

images    The following converse of 2.1.2.25 , “if z = f ( images ) is in images * and f is total, then f Images images ” is not true. A counterexample is provided by the Ackermann function. However, “if z = f ( images ) is in images * and f is total, then f Images images ” is true. More on the Ackermann function in Section 2.4 .    images

2.1.2.26 Exercise. Using unbounded search, prove that if z = f ( images ) is in images * and f is total, then f Images images . images

2.1.2.27 Definition. (Bounded Quantifiers) The abbreviations (∀ y ) < z R ( z , images ) and (∃ y ) < z R ( z , images ) stand for (∀ y ) ( y < z → R ( z , images )) and (∃ y ) ( y < z ⋀ R ( z , images )), respectively, and similarly for the nonstrict inequality “≤”. images

2.1.2.28 Theorem. images * 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 , images ) ≡ ¬(∃ y ) < z ¬ R ( y , images ).

Let then R ( y , images ) Images images * and let us give the name Q ( z , images ) to (∃ y ) < z R ( y , images ). We note that Q (0, images ) is false (why?) and Q ( z + 1, images ) ≡ Q ( z , images ) ⋁ R ( z , images ). Thus,

images images

2.1.2.29 Corollary. images * 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 images and images , respectively, where images and images by definition. Prove that images and images are closed under both operations; i.e., if f is in images (respectively, in images ), then so are images and images . images

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 , images ), for all z , images , stands for

images

We define “( μy ) ≤ z ” to mean “( μy ) < z + 1 . images

2.1.2.32 Theorem. images is closed under the bounded search operation ( μy ) < z . That is, if λ y images . f ( y , images ) Images images , then λ z images .( μy ) < z f ( y , images ) Images images .

Proof. Set g = λ z images .( μy ) < z f ( y , images ). Then the following primitive recursion settles it:

g (0, images ) = 1

                                  g ( z + 1, images ) = if g ( z , images ) < z then g ( z , images )

                                              else if f ( z , images ) = 0 then z

                                else z + 1 images

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. images

2.1.2.34 Corollary. images is closed under the bounded search operation ( μy ) ≤ z .

2.1.2.35 Exercise. Prove the corollary. images

2.1.2.36 Corollary. images is closed under the bounded search operations ( μy ) < z and ( μy ) ≤ z .

Consider now a set of mutually exclusive relations R i ( images ), i = 1, ..., n , that is, R i ( images ) ⋀ R j ( images ) is false for each images 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 images ) given below:

images

where, as is usual in mathematics, “if R j ( images )” is short for “if R j ( images ) is true” and “otherwise” is the condition ¬( R 1 ( images ) ⋁ · · · ⋁ R n ( images )). 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 ( images ), i = 1, ..., n are in images and images * , 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

images images

2.1.2.38 Corollary. Same statement as above, replacing images and images * by images and images * , 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 , images ) means ( μy ) < z χ R ( y , images ). images

Thus, if R ( y , images ) Images images * (resp. Images images * ), then λ z images .( μy ) < z R ( y , images ) Images images (resp. Images R ), since χ R Images images (resp. Images images ).

2.1.2.40 Example. The following are in images or images * 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 images 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 ) = images .

(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 ). images

images    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.      images

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?).  images

2.1.2.43 Exercise. Prove that λ x .⌊log 2 x ⌋ Images images . Remove the undefinedness at x = 0 in some convenient manner. For example, arrange that ⌊log 2 0⌋ = 0 images

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

images images

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 ) images 1

Note that

(a) λ iz .( z ) i and λ z.lh ( z ) are in images .

(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.

images    The symbol [. . .] for numerical sequence coding is not standard. Usually, images . . . images 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.   images

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, images ), f (1, images ), ..., f ( x , images )}, 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 λ images n . b ( images n ) and the iterator λ x images n z.g ( x , images n , z )—by course-of-values recursion if for all x , images n the following equations hold:

images

where λ x images n . H ( x , images n ) is the history function, which is given “at x ” (for all images n ) by

[ f (0, images ), f (1, images ), ..., f ( x , images )] images

images    Compare with the general case in 1.7.0.29 . Here, totalness allows a neat coding of the “history” { f (0, images ), f (1, images , ..., f ( x , images )} as a single number that depends on x and images . 59 Of course, 1.7.0.29 guarantees the existence of an f satisfying the schema (1) above.   images

2.1.2.46 Exercise. Prove that f given by (1) is total.

Hint. Use strong induction on x . images

The major result here is:

2.1.2.47 Theorem. images is closed under course-of-values recursion .

Proof. So, let b and g be in images . We will show that f Images images . It suffices to prove that the history function H is primitive recursive, for then f = λ x images n .( H ( x , images n )) x and we are done by Grzegorczyk substitution. To this end, the following equations—true for all x , images n —settle the case:

images images

The same proof with trivial adjustments yields:

2.1.2.48 Corollary. images 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 images . 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 images .

F 0 = 0                 
F n +1 \= if n = 0 then 1
                               else ( H n ) n + ( H n ) n images 1 images

images    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 images . What can we learn from the partial recursive H that is defined as follows? (Note the use of “≃” this time.)

images

First off, the domain of λ x.H ( x , images n is either images , or a set of the form { i Images images : i < k } for some k (that depends on the chosen fixed images n ). We call this latter set an initial segment of images .

Let us verify this claim. We fix a images n . If λ x.H ( x, images n ) is total, then there is nothing to prove. Otherwise, let x = x 0 be smallest such that H ( x, images n ) ↑. By induction on x we see that H ( x, images 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, images 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, images 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, images n ) = [ b ( images n )] (why “=”?). If H ( x , images n ) = [ a 0 , · · · , a x ] and x + 1 < x 0 ( I.H. ), then the second equation of (1) yields H ( x + 1, images n ) = [ a 0 , ..., a x , g ( x , images , H ( x , images ))], as needed.

Let us now set

images

Thus we have the validity of the course-of-values recurrence, for all x and images n

images

By (2) and the earlier remarks, dom( f ) = dom( H ) and in particular, for each fixed images n , dom(λ x.f ( x , images n )) is either images or a set of the form { i Images images : i < k } for some k (that depends on the chosen fixed images 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:   images

2.1.2.51 Theorem. images is closed under the schema of course-of-values recursion, that is, (1) of 2.1.2.50. For any fixed images _n , the subsidiary function f defined by (2) is either total in x or is an initial segment of images . _Moreover it satisfies the recursion (3).

2.1.3  Simultaneous Primitive Recursion

Taking B = images k in 1.7.0.27 , and letting h and g be total functions from images n and images n +1 × images k respectively to images k , and replacing ≃ by =, (1) in said example becomes

images

Now f, h, and g are k -tuple valued, so they are not number-theoretic functions (which must have a right field equal to images , by definition; cf. 2.1.1.6 ). However, if we write them in terms of their components, for example,

f ( x , images n ) = images f 1 ( x , images n ), ..., f k ( x , images n ) images

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).

images

Hilbert and Bernays proved the following:

2.1.3.1 Theorem. If all the h i and g i are in images (resp. images ), then so are all the f i obtained by the schema (2) of simultaneous recursion.

Proof. Define, for all x, images n , and images k ,

images

We readily have that H Images images (resp. Images images ) and G Images images (resp. Images images )—and, in particular, λ x images n z.G ( x , images n , ( z ) 0 , ..., ( z ) k −1 ) Images images (resp. Images images )—depending on where we assumed the h i and g i to be. We can now rewrite schema (2) as

images

By the above remarks, F Images images (resp. Images images ) 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 , images n , f i ( x , images n ) = ( F ( x , images n )) i −1 . images

2.1.3.2 Example. We saw one way to justify that λ x.rem ( x , 2) Images images 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 Images images :

images

Here is a way, via simultaneous recursion, to obtain a proof that f Images images , 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

images

images    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 “ images 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.   images

2.1.3.3 Example. We saw one way to justify that λ x . ⌊ x /2⌋ Images images in 2.1.2.40. A direct way is the following.

images

where rem is in images 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

images

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 : images × images → images is called a pairing function. images

images    2.1.4.2 Remark. By 1.2.0.25 there is an onto g : images → images × images such that g ( J ( x , y )) = images x , y images for all x , y in images . g is pair-valued (“vector”-valued) thus not a number-theoretic function. As in the previous subsection, we may write, for all z Images dom ( g ),

g ( z ) = images K ( z ), L ( z ) images

that is, decompose g as a pair of functions images K , L images 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 images ,

images

and

images

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 images , we cannot expect

images

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 Images dom ( images K , L images )” instead? images

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 images , for example, letting, for all z Images images ,

images

Clearly, we still get ( images J ) = 1 Images , that is, images ( J ( x, y )) = images x , y images for all x and y in images , simply because J ( x, y ) Images dom( g ). Of course, by preceding remarks, ( J images ) = 1 Images must fail unless J is onto images .   images

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 images .

This J is not onto. For example, 5 Images ran( J ). Nevertheless, K and L are total—because λ iz . ( z ) i is; indeed is in images —and unlike the explicit extension of g in the preceding remark, this fact did not require our intervention. images

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 ? images

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 images .

This J is not onto. Again, 5 Images ran( J ). Nevertheless, K and L are total—because λ iz . exp ( i, z ) is; indeed is in images —and unlike the explicit extension of g in the preceding remark, this fact did not require our intervention either. images

images    Clearly, for any distinct primes p i and p j , the function images is pairing, with projections λ z . exp ( i, z ) and λ z . exp ( j, z ).   images

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 images !

Its projections can be easily calculated in a manner that readily establishes their primitive recursiveness. K z \= exp (0, z ) and

images images

images    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.   images

2.1.4.6 Example. J = λ xy .2 x + y +2 + 2 y +1 is pairing. That it is in images 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

images

Now, z = 2 ⌊log 2 z ⌋ + 2 y+2 , thus

images

We obtain L z \= ⌊log 2 ( z images 2 ⌊log 2 z ⌋ )⌋ images 1 and, from (1), K z \= ⌊log 2 z ⌋ images ( Lz + 2). From Exercise 2.1.2.43 we conclude that K and L are indeed in images . images

images    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 images is to compute as follows:

images

and

images

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 images .

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? images    images

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 image image image .

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 image , hence

image

Then, image and therefore image . By (1), image

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 image and image            image

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 image : image and image .           image

image    2.1.4.10 Remark. It is a trivial exercise to verify that the 1-1 ness of J implies that of image , for any n ≥ 2. Moreover, if J is onto image , then so is image (cf. Exercise 34 in Section 1.8 ).

The primitive recursive K and L give rise to primitive recursive projections, denoted by image for each fixed n , and each 1 ≤ i ≤ n .

These will satisfy image image = 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 image , then

image

where we wrote L i for

image

for any fixed i ( i – 1 compositions with itself). image

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 image if n = 0; image if n = 1; and image otherwise. We denote by lg ( z ) the sequence length, thus we set lg = K . image

image Ontones of J, and hence of image , 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).           image

The projections, denoted by image , for non zero lg ( z ) and 1 ≤ i ≤ lg ( z ), are

image

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 image image image .

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 ) : image × A → A given by the following definition:

2.1.5.1 Definition. (Pure Iteration) We say that λ xy · f ( x , y ) : image × A → A — where A is some set—is defined from λ x · g ( x ) : A → A by pure iteration iff, for all x image image and y image 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 image image , f ( k , y ) ≃ image , while we adhere to the convention that g 0 = 1 A . image

image    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 image image image , λ xy · g x ( y ) image image image . image

2.1.5.3 Example. Let g : image × image → image × image be given by g ( x , y ) = image y , x image . What is g z (0, 1)? It is image rem ( z , 2), rem ( z + 1, 2) image . Cf. Example 2.1.3.2. image

2.1.5.4 Example. Let g : image × image → image × image be given by g ( x , y ) = image y , x + 1 image . 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 image 0, 0 image (depicted as image 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.

image

Thus, g z (0,0) = image Cf. Example 2.1.3.3 . image

2.1.5.5 Example. Let g : A n → A n be such that its first component is the “identity” function, in the sense, image for all image a , . . . image image dom( g ) (cf. Exercise 1.8.23 ). In other words, if g = image g 1 . . . , g n image is the decomposition of g into its components, then g 1 ( image ) = x 1 for all image in its domain.

We will show that the first component of image is also the identity.

Indeed, we can show this by induction on z : For z = 0, g 0 ( image ) = image image image , hence image , for all image . For fixed z , assume (I.H.) that

image , for all image on which the left hand side of = is defined    (*)

that is, g z ( image ) = image x 1 , . . . image . Thus,

g z +1 ( image ) = g ( x 1 , . . .) = 62 image x 1 , g 2 ( image x 1 , . . . image ), . . ., g n ( image x 1 , . . . image ) image       image

image    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 λ image . g z ( image ) as the “f” here.

(2) With g as in 2.1.5.5 , let us set f = λ image z · g z ( image ). Then f ( image , z ) = image x 1 , . . . image 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 = image g 1 , ..., g n image [and f = image f 1 , ..., f n image in (1)], where g k ( image ) = x k [and f k ( image ) = x k in (1)], for all image in the respective domains.      image       image

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.

image

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

image

We may write a primitive recursion for F :

image

Noting that (omitting bracketing) image , for 1 ≤ i ≤ n ; and image we see that schema ( B ) has the form

image

where

image

and image

A trivial induction on x shows that F ( x , image ) = G x H ( image ). 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. image