Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Hedman. A First Course in Logic, 2004 (Oxford)

.pdf
Скачиваний:
140
Добавлен:
10.08.2013
Размер:
7.17 Mб
Скачать

310

Computability and complexity

Definition 7.21 Let f x, y) be a (k+1)-ary function on the non-negative integers. We denote by usyf x, y) the (k)-ary function defined as follows. For a given k-tuple x¯, usyf x, y) = z if and only if f x, y) is defined for each y ≤ z and z is least such that f x, z) = 0. If no such z exists, then x¯ is not in the domain of usyf x, y) .

Definition 7.22 Let S be a set of functions on the non-negative integers. The set is closed under unbounded search if the following holds. If f x, y) is in S, then so is the function usyx, y).

Definition 7.23 The set of recursive functions is the smallest set containing the basic functions and closed under composition, primitive recursion, and unbounded search.

Every recursive function is computable. To verify this, consider the unbounded search process. Suppose that f x, y) is computable. To compute usyf a, y) for a given input a¯, follow these steps:

(1)Let n = 0

(2)Compute f a, n)

(3)If f a, n) = 0, then usyf a, y) = n.

Otherwise add 1 to the value of n and go to (2).

Thus, usyf a, y) is computed in a finite number of steps provided that a¯ is in the domain of usyf x, y). If a¯ is not in the domain of usyf x, y), then these three steps will produce no output (the algorithm will either be unable to compute step (2) for some n or it will form an infinite loop).

Conversely, we claim that every computable function is recursive. In particular, the Ackermann function is recursive. We prove this as a consequence of Kleene’s Recursion theorem 7.38 of Section 7.4. Thus, we show that the Ackermann function is recursive without providing an explicit definition of this function in terms of unbounded search. We leave this explicit definition as Exercise 7.12.

The assertion that every computable function is recursive is known as Church’s thesis. Section 7.4 provides evidence for Church’s thesis. Not only do we show that the Ackermann function is recursive, but we also prove that all functions computable by programs in a specific programming language are recursive. We do not prove Church’s thesis. Such a proof would have to consider every conceivable programming language. This is not feasible. Moreover, even if we were to somehow succeed in this task, then this still would not su ce as a proof of Church’s thesis.

To fully understand Church’s thesis, we must make the distinction between functions that are computable by a computer program and those functions that are computable in the intuitive sense. A function is “programmable” if

Computability and complexity

311

there is a computer program (in some conventional programming language) that computes the function. It need not be feasible to execute the program in a reasonable amount of time or space. A function is “intuitively computable” if it can somehow be computed by some algorithm. Whereas the notion of a recursive function is precise, the notions of “programmable” and “intuitively computable” are increasingly more vague. From these definitions, we have the following two inclusions:

Recursive

 

Programmable

 

Intuitively Computable

 

Functions

Functions

Functions

.

Church’s thesis implies that each of these three sets contain the same functions. There are two possible scenarios in which this thesis is false. One possibility is that there exists a clever computer capable of computing a nonrecursive function. We claim that this is not the case. That is, we claim that the first of the above inclusions is not proper. We provide evidence for this following Theorem 7.38 of Section 7.4. The other scenario involves the second inclusion.

Let us temporarily entertain the possibility that there exist functions that are computable by some algorithm that cannot be implemented into a computer program. For example, consider the function π(n) = the nth digit in the decimal expansion of π. This function is intuitively computable since we have the following algorithm: construct a really big circle, measure the circumference and diameter, and divide (“really big” depends on n). Likewise, consider the function f (n) = |1000 · sin n| (rounded to the nearest integer). We can compute this function by constructing a really big triangle having an angle of n radians and taking the ratio of two sides. If we are trying to program a computer to evaluate these functions, then these algorithms do not lend much insight. There do, of course, exist computer algorithms that compute π(n) and f (n) (for example, we can use the Taylor series to compute the sine). However, it seems plausible that there exist other algorithms that cannot be carried out by a computer. Church’s thesis states that this is not the case: any function that is computable in the intuitive sense is recursive. From this point of view, Church’s thesis is not a statement of mathematics, but a statement of faith that precludes the possibility of proof (although disproof is possible).

We make no assumptions regarding the veracity of Church’s thesis. We focus our attention on the set of recursive functions. We show in Section 7.4 that these functions are equivalent to the functions that are computable in a certain computer language. Moreover, we claim that these are precisely those functions that are computable by a program in C++ (or Basic or Cobol or Maple). This provides evidence in support of Church’s thesis, but this not our aim. Regardless of whether or not Church’s thesis is true, the set of recursive functions is of natural interest. Henceforth, when we refer to the computable functions we mean

312

Computability and complexity

a function in this precisely defined set. Our aim in this chapter is to investigate this set of computable functions and the corresponding concept of decidability.

7.2 Computable sets and relations

Let A be a subset of the non-negative integers. The characteristic function of A (denoted χA(x)) is defined as follows:

1 x A χA(x) = 0 x A.

The set A is said to be recursive if its characteristic function is recursive. Likewise, A is said to be primitive recursive if its characteristic function is. These definitions can be extended to any relation R on N {0}. That is, the recursive (and primitive recursive) subsets of (N {0})k for k > 1 are defined in the same manner that we have defined the recursive and primitive recursive subsets of N {0}.

To each relation R on the non-negative integers there is an associated decision problem: namely, the problem of determining whether or not a given tuple x¯ is in the set R. This decision problem is said to be decidable if and only if R is a recursive relation. By definition, every decision problem corresponds to some relation. So to study recursive relations is to study the set of all decidable decision problems. In this section, we restrict our attention to the primitive recursive relations. In Section 7.5 we consider the wider set of recursive relations and demonstrate (in Section 7.6) various subsets of N {0} that are not recursive.

Example 7.24 Consider the binary relation x < y. The characteristic function for this relation is defined by χ<(x, y) = 1 if x < y and χ<(x, y) = 0 otherwise. This function can be defined as a composition of primitive recursive functions:

χ<(x, y) = 1 (x − y).

It was shown in Proposition 7.9 that sub(x, y) = x − y is primitive recursive. It follows that the relation x < y is also primitive recursive.

Primitive recursive relations allow us to define primitive recursive functions by cases. For example, consider the function f (x) defined by cases as follows.

f (x) =

g(x) if x < 10 h(x) otherwise.

If g(x) and h(x) are both primitive recursive, then so is f (x). More generally, we have the following.

Computability and complexity

313

Proposition 7.25 Let R1, . . . , Rn be disjoint k-ary relations

and let

g1x), . . . , gnx) be k-ary functions. If each of these functions and relations is primitive recursive, then so is the function defined by cases as follows

hx) =

g2

x)

if R2

x)

 

 

g1

x)

if R1

x)

 

. . . . . .

 

 

 

 

 

 

 

 

 

 

 

 

 

 

gkx)

if Rkx).

 

 

 

 

 

 

Proof We have

 

 

 

 

 

f x) = g1x) · χ1x) + g2x) · χ2x) + · · · + gkx) · χkx),

where χix) denotes the characteristic function for the relation Rix) (for i = 1, . . . , k).

In this section, we show that several familiar relations (in addition to a < b) are primitive recursive. We also show that, given two primitive recursive relations A and B on the non-negative integers, the relations A B, A ∩ B, A × B, and other relations are also primitive recursive. Rather than considering these relations one-by-one and proving that each is primitive recursive, we instead take advantage of our background in first-order logic. We show that if a relation is definable by a quantifier-free formula in the vocabulary of arithmetic, then that relation is primitive recursive.

Let N0 = (N {0}|+, ·, 0, 1) be the structure having the non-negative integers as an underlying set that interprets the vocabulary Var = {+, ·, 0, 1} in the usual way.

Proposition 7.26 Let A be a definable subset of N0. If A is definable by a quantifier-free Var-formula, then A is primitive recursive.

Proof Let ϕA(x1, . . . , xn) be a Var-formula that defines the k-ary relation A. We show that A is primitive recursive by induction on the complexity of ϕA. However, we do not proceed in the usual order. We first prove the induction step and lastly consider the case where ϕA is atomic.

Suppose that θx) and ψx) are Var-formulas that define primitive recursive subsets of N0. Let B be the relation defined by θ and let C be the relation defined by ψ. Then the characteristic functions χB and χC are both primitive recursive. We must show that the characteristic function of A is also primitive recursive.

If ϕAx) ≡ θx), then χA and χB are the same primitive recursive function. If ϕAx) is the formula ¬θx), then χAx) is 1 if and only if χB x) is 0.

 

 

So χAx) = 1 − χB x). Since both χB x) and sub(x, y) = x − y are primitive recursive, so is χAx).

314

Computability and complexity

 

Now suppose ϕAx) is the formula θx) ψx). Then χAx) equals the

composition m(χB x), χC x)) = χB x) · χC x).

 

In any of these cases, χAx) is primitive recursive. This concludes the induc-

tion step of the proof. It remains to be shown that χAx) is primitive recursive

¯ V

in the case where ϕA(X) is an atomic ar-formula.

Since there are no relations in the vocabulary, atomic Var-formulas have the form t1 = t2 for Var-terms t1 and t2. Each term is a composition of the functions + and · applied to the constants and variables. So each Var-term may be regarded as a polynomial px) having natural numbers as coe cients. If ϕAx) is atomic, then it must have the form p1x) = p2x). By Proposition 7.12, each of the polynomials p1x) and p2x) are primitive recursive functions. We must show that the relation of equality is also primitive recursive.

We previously demonstrated that the relation x < y is primitive recursive. It follows that y ≤ x (the negation of x < y) is also primitive recursive. Likewise, x ≤ y is a primitive recursive relation. Finally, the relation x = y, defined as x ≤ y y ≤ x, is primitive recursive. (We are using the fact that the primitive recursive relations are closed under negations and conjunctions. This was proved as part of the induction step.)

If ϕAx) is atomic, then χAx) is the composition χeq(p1x), p2x)), where χeq(x, y) = 1 if x = y and is otherwise zero. Since it is the composition of primitive recursive functions, χAx) is primitive recursive.

This completes the base step for the induction. We conclude that every quantifier-free Var-formula defines a primitive recursive subset of N0.

The converse of Proposition 7.26 does not hold. In the next chapter we prove that every primitive recursive relation is definable (see Corollary 8.15). However, not every primitive recursive relation is definable by a quantifier-free formula. The formula that defines a primitive recursive relation may require quantifiers.

Definition 7.27 Let F be a set of Var-formulas. We say that F is closed under bounded quantifiers if for any ϕ(x, y) F , the formula y(y < x ϕ(x, y)) is also in F where y < x is an abbreviation for the formula z(y + z = x). (The formula ϕ(x, y) may have free variables other than x and y.)

Let ∆0 be the smallest set of Var-formulas containing the atomic formulas that is closed under equivalence, negation, conjunction, and bounded quantifiers. Note that the negation of the formula y(y < x ϕ(x, y)) is equivalent to the formula y(y < x → ¬ϕ(x, y)). So in any ∆0 formula, each variable y that is quantified by either or is bounded by another variable as y < x. That is, the bound variables are bounded by free variables. In particular, each ∆0 sentence must be quantifier-free.

Computability and complexity

315

A relation is primitive recursive if and only if it is definable by a ∆0 formula. We presently prove one direction of this fact. The other direction shall become apparent after Section 8.3 of the next chapter and is left as Exercise 8.6.

Proposition 7.28 Let A be a definable subset of N0. If A is definable by a ∆0 formula, then A is primitive recursive.

Proof We must add one step to the proof of the previous proposition. Suppose that ϕ(x, y) defines a primitive recursive subset A of N0. We must show the formula y(y < x ϕ(x, y)) also defines a primitive recursive subset. For convenience, we assume that x and y are the only free variables of ϕ(x, y) (this assumption does not alter the essence of the proof).

Let χA(x, y) be the characteristic function for A. Since this function is

primitive recursive,

so

is

 

the

function sumχ(x, y) =

z<y χA(x, z) by

Pro-

position 7.18. It follows that the function g(x) =

sumχ(x, x) is also primitive

 

 

 

recursive.

Note that 1

g(x) equals 0 if χ

A

(x, z) =

1 for some z < x and

 

 

 

 

 

 

 

 

 

 

 

 

1

g(x)

equals

1.

From this observation,

we see that the

func-

otherwise

 

tion 1 (1 − g(x)) is the characteristic function for the set defined by y(y < x ϕ(x, y)). It follows that this is a primitive recursive set.

Propositions 7.26 and 7.28 allow us to succinctly show that certain functions and relations are primitive recursive. The aim for the remainder of this section is twofold. One aim is to demonstrate some of the many familiar functions and relations that are primitive recursive. The other aim is to show that a specific binary function, namely pf (x, i), is primitive recursive. The name “pf” bestowed to this function is an abbreviation for “prime factorization.” We shall make use of this function and the fact that it is primitive recursive in Section 7.4.

Prior to defining the function pf (x, i), we define the relations div(x, y) and prime(x). For any pair (x, y) of non-negative integers, the relation div(x, y) says that x divides y and prime(x) says that x is prime. The relation div(x, y) holds if and only if there exists a z such that x · z = y. Clearly, if such a z exists, then z is at most y. So div(x, y) is definable by the ∆0 formula

z(z < y x · z = y) x = 1 (y = 0 ¬x = 0).

Likewise, prime(x) is defined by the formula

z(z < x → (z = 1 ¬div(z, x))) (¬x = 1).

Since these formulas are ∆0, the relations div(x, y) and prime(x) are primitive recursive by Proposition 7.28.

There are infinitely many primes. Let p1, p2, p3, . . . represent the enumeration of the primes in increasing order. So p1 = 2, p2 = 3, p3 = 5, and so forth. We claim that the function pr(i) = pi is primitive recursive. To make this function

316

Computability and complexity

total, let us set pr(0) = 0. This function can be defined by primitive recursion. Let h(x) = Z(x) and let g(x, y) be the least prime number greater than y. To verify that g(x, y) is primitive recursive, note that we can define this function using bounded search. The least prime number greater than y must be less than 2y. (“Chebychev proved it, and Erd¨os proved it again, there is always a prime between n and 2n.”) The function pr(i) is defined as follows:

pr(0) = h(0) = 0,

pr(n + 1) = g(n, pr(n)).

We now define the prime factorization function pf (x, i). Every natural number x can be factored as

x = pa11 pa22 . . . pakk ,

where pi denotes the ith prime number. Moreover, the exponents ai are uniquely determined by x. This is the Fundamental Theorem of Arithmetic. We define pf (x, i) to be the exponent ai that occurs on the ith prime in the prime factorization of x. To make this a total function, we define pf (x, i) to be 0 if x = 0 or i = 0.

Proposition 7.29 The function pf (x, i) is primitive recursive.

Proof We sketch the proof. The function pf (x, i) equals y if and only if div(pr(i)y, x) and ¬div(pr(i)(y+1), x) both hold. Such a number y must be less than x (since px > x for all primes p and integers x). So we can define pf (x, i) in terms of the primitive recursive function pr(i), the primitive recursive relation div(x, y), and the primitive recursive operation of bounded search. It follows that pf (x, i) is primitive recursive.

7.3 Computing machines

In the 1930s, Alan Turing described a theoretical computing machine to capture the notion of computability. Turing’s thesis states that every function that is intuitively computable can be computed by a Turing machine. Modern computers may be viewed as crude approximations of Turing’s machine (crude since they do not have infinite memory). Variations of Turing’s machine known as register machines were developed in the 1960s by Shepherdson, Sturgis, and others. It was shown that each of these theoretical machines have the same computing power. The functions computable by either a Turing machine or a register machine are precisely the recursive functions. In light of these results, Turing’s thesis is equivalent to Church’s thesis. Henceforth, we refer to this as the Church–Turing thesis.

Computability and complexity

 

317

In this section, we describe a variation of the

register machines.

This

machine executes programs written in a specific programming language that we shall describe. Functions computable by programs in this language are called T-computable. At the conclusion of this section, we prove that every recursive function is T -computable. We prove the converse of this in the next section. So the computing machine we describe has the same computing power as any register machine or Turing machine.

We now describe our programming language. As we have previously indicated, it does not matter which programming language we choose. If a function is computable by a program in PASCAL, then this program can be translated to a program in C++ or any other programming language. For convenience and definiteness, we use a simplified programming language we call T ++. This language is convenient because it has only four types of commands. Of course, if we actually wanted to program a computer to perform a complicated task, then this language would not be so convenient. For each i N, T ++ has the following commands:

Add i, Rmv i, RmvP i, and GOTO i.

A program in T ++ is a finite sequence of commands.

We now describe a machine that runs a given T ++ program P . This is called a turnip machine or, more simply, a T -machine. The machine consists of an enumerated row of bins. Each bin contains turnips. Let Bi denote the ith bin. We assume there are enough bins (and turnips) to carry out the program. Some of these bins may be empty. Whereas the bins are enumerated B1, B2, B3, . . . , the commands that constitute the program are enumerated (1), (2), . . .

(the latter sequence is finite).

To run program P , the T -machine begins by reading the first command. We now describe how the T -machine executes each of the four possible commands. Suppose that the machine is reading command (10) of program P .

If this command is Add i, then the machine puts one turnip in bin Bi and then proceeds to the next command (namely, command (11)).

If the tenth command is RmvP i, then there are two possibilities. If bin Bi is empty, then the machine does nothing and proceeds to the next command. Otherwise, the turnip machine removes one turnip from bin Bi and then goes to the previous command (namely, command (9)).

If the tenth command is Rmv i, then the T -machine removes a turnip from bin Bi (if there is one) and then, regardless of whether or not there was a turnip to be removed, proceeds to the next command (namely, (11)).

Finally, the command GOTO i causes the turnip machine to go to command (i) of program P .

318

Computability and complexity

 

The T -machine continues to operate until it comes to a line of the program

that does not exist. For example, the following program causes the T -machine to halt immediately without doing anything:

(1) GOTO 12.

It is possible that the T -machine will never halt as the following T ++ program demonstrates:

(1) Add 4

(2) RmvP 4.

By adding one line the beginning of the previous program we obtain:

(1)RmvP 4

(2)Add 4

(3)RmvP 4.

If there is a turnip in bin B4 when we run this program, then the T -machine removes a turnip and halts. Otherwise, if B4 is empty, the T -machine will never halt.

The number of turnips in each bin when the T -machine halts (if it halts) depends on how many turnips were in the bins at the outset. Thus, each T ++ program determines a function. In fact, each program P determines many functions. For each k N, we describe a k-ary function P (k) on the non-negative integers. Given (x1, . . . , xk) as input, put xi turnips in bin Bi for i = 1, . . . , k and leave the bins Bj empty for j > k. Run program P . We define P (k)(x1, . . . , xk) to be the number of turnips in bin B1 when the machine halts. If the T -machine does not halt, then P (k)(x1, . . . , xk) is undefined.

Definition 7.30 Let f be a partial or total k-ary function on the non-negative integers. We say that f is T-computable if f is P (k) for some T ++ program P . That is, f and P (k) have the same domain and f (x1, . . . , xk) = P (k)(x1, . . . , xk) for any (x1, . . . , xk) in this domain.

Of course, the actual hardware for the T -machine is irrelevant. We could use cabbage instead of turnips. In fact, the concept of a T -machine does not require any vegetables. Modern computers can be used to simulate turnip machines. From now on, we assume that a T -machine is a computer that has been programmed to carry out the above commands. We view each Bi as a program variable that may take on any non-negative integer value.

Although they may seem primitive, T -machines are capable of computing any recursive function.

Computability and complexity

319

Proposition 7.31 Every recursive function is T -computable.

Proof We first show that the basic functions are T -computable. The successor function s(x) corresponds to the one-lined program: (1) Add 1. The zero function is computed by the following T ++ program.

(1)Rmv 1

(2)RmvP 1.

Now consider the projection function pki (x1, x2, . . . , xk) = xi (for i ≤ k). If i = 1, then this function is computed by the program (1) GOTO 12 or any other program that causes the T -machine to do nothing. For i > 1, consider the following program.

(1)Rmv 1

(2)RmvP 1

(3)Add 1

(4)RmvP i

(5)Rmv 1.

This program moves the contents of Bi to B1. The first two lines set B1 to zero. Lines (3) and (4) successively increase B1 while decreasing Bi. When Bi reaches zero, we will have increased B1 one too many times. The final line of the program corrects this.

We claim that the set of T -computable functions is closed under both composition and primitive recursion. We leave the verification of this as Exercise 7.9. It follows that every primitive recursive function is T -computable.

It remains to be shown that the T -computable functions are closed under unbounded search. Suppose that the function h(x1, . . . , xn, y) is T -computable. We describe a T ++ program that computes the least value of y for which h(x1, . . . , xn, y) = 0.

(1)ZERO Bn+1

(2)COMPUTE h(B1, . . . , Bn, Bn+1) STORE IN Bn+2

(3)GOTO 5

(3) GOTO 8

(5)RmvP n + 2

(6)MOVE Bn+1 TO B1

(7)GOTO 10

(8)Add n + 1

(9)GOTO 2.